mirror of
https://github.com/saltbo/zpan.git
synced 2026-09-01 15:49:00 +08:00
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:
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user