fix(downloader): nil-safe isAria2RPCDisconnected to stop a startup panic

isAria2RPCDisconnected called err.Error() unconditionally, so a nil error
panicked (nil pointer deref). findSeed reaches it with a nil error whenever
tellStatus succeeds but the status isn't a seed — which crashed the downloader at
startup while restoring a retained seed from the ledger. Guard nil -> false.
This commit is contained in:
saltbo
2026-06-19 19:28:18 -04:00
parent a803b2d6f0
commit 23ded65e6f
2 changed files with 11 additions and 0 deletions
+3
View File
@@ -1001,6 +1001,9 @@ func (a Aria2) reconnect(ctx context.Context, aria **arigo.Client) error {
}
func isAria2RPCDisconnected(err error) bool {
if err == nil {
return false
}
return errors.Is(err, rpc2.ErrShutdown) || errors.Is(err, io.ErrClosedPipe) || strings.Contains(err.Error(), "connection is shut down")
}
+8
View File
@@ -230,6 +230,14 @@ func TestAria2SeedTimeMinutes(t *testing.T) {
}
}
func TestIsAria2RPCDisconnectedNilSafe(t *testing.T) {
// findSeed/findTask call this with a nil error when tellStatus succeeded but
// the status wasn't what we wanted; it must not panic on err.Error().
if isAria2RPCDisconnected(nil) {
t.Fatal("nil error must not be treated as disconnected")
}
}
func TestShouldAttachExistingAria2Task(t *testing.T) {
// 'interrupted' (how restart resumes a task) must attach to the session-
// restored download rather than re-add (which duplicates + orphans it).