From ac3c44a9666a12ee9c1925092999b1998a505abc Mon Sep 17 00:00:00 2001 From: positiveblue Date: Sun, 13 Feb 2022 22:25:39 -0800 Subject: [PATCH] sidecar: Init mailbox after server restarts Whenever we are are unable to receive a sidecar packet in an auto sidecar negotiator try to init its mailbox. This will allow us to continue reading/writting in the mailbox in cases where the server went down and came back. --- auto_sidecar.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/auto_sidecar.go b/auto_sidecar.go index 2ba1373..7968a99 100644 --- a/auto_sidecar.go +++ b/auto_sidecar.go @@ -314,6 +314,23 @@ func (a *SidecarNegotiator) autoSidecarReceiver(ctx context.Context, select { case <-retryTimer.backOff(backoffLabel): + // It is possible that we were not able to receive the + // packet because the server went down. In that case, + // we will try to init the sidecar mailbox again. + // There is no need to log/check this error. There are + // three possibilities: + // + // 1) If the error was not related with the sever being + // down, we will get an `AlreadyExists` error. + // + // 2) If the server is back, we will be able to reconnect + // successfully and receive the sidecar pkt in the next + // iteration. + // + // 3) If the server is down, we won't be able to reconnect. + _ = a.cfg.MailBox.InitSidecarMailbox( + recipientStreamID, startingPkt.ReceiverTicket, + ) continue case <-a.quit: return @@ -588,6 +605,21 @@ func (a *SidecarNegotiator) autoSidecarProvider(ctx context.Context, select { case <-retryTimer.backOff(backoffLabel): + // It is possible that we were not able to receive the + // packet because the server went down. In that case, + // we will try to init the sidecar mailbox again. + // There is no need to log/check this error. There are + // three possibilities: + // + // 1) If the error was not related with the sever being + // down, we will get an `AlreadyExists` error. + // + // 2) If the server is back, we will be able to reconnect + // successfully and receive the sidecar pkt in the next + // iteration. + // + // 3) If the server is down, we won't be able to reconnect. + _ = a.cfg.MailBox.InitAcctMailbox(streamID, acct.TraderKey) continue case <-a.quit: return