From 8a975f9a3130791597eef003c25459988c31b6e6 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Fri, 21 Jun 2024 21:55:04 +0900 Subject: [PATCH] rpc: handle response with Identify opcode as retryable Sometimes arRPC would just send a response with the Identify opcode and `{"cmd":""}`. It is unclear what causes this and the easiest way to recover that I'm aware of is to close the connection and start a fresh one. Signed-off-by: Ophestra Umiker --- rpc.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rpc.go b/rpc.go index 31a1136..57b2258 100644 --- a/rpc.go +++ b/rpc.go @@ -146,8 +146,18 @@ func validateRaw[T nonceEventCommandTracer](opcode uint32, event, command, nonce if err == nil { switch { case opcodeR != opcode: - debugResponse(resp) - err = fmt.Errorf("received unexpected opcode %d", opcodeR) + // the socket is still open however + // as far as I'm aware this state is not recoverable + // therefore we close the connection and advise a retry + if opcodeR == Identify { + // clean up as much as possible + _ = d.Close() + // advise retry + err = ErrAgain + } else { + debugResponse(resp) + err = fmt.Errorf("received unexpected opcode %d", opcodeR) + } case !resp.nonce(nonce): err = ErrNonce case eventR != nil: