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 <cat@ophivana.moe>
This commit is contained in:
Ophestra Umiker 2024-06-21 21:55:04 +09:00
parent 72d6a8e95c
commit 8a975f9a31
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
1 changed files with 12 additions and 2 deletions

10
rpc.go
View File

@ -146,8 +146,18 @@ func validateRaw[T nonceEventCommandTracer](opcode uint32, event, command, nonce
if err == nil {
switch {
case opcodeR != opcode:
// 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: