-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client/core: safe swap and comms tweaks #663
Conversation
ff29f48
to
34f8564
Compare
// reconnect begins reconnection immediately. | ||
func (conn *wsConn) reconnect() { | ||
conn.setConnected(false) | ||
conn.reconnectCh <- struct{}{} | ||
} | ||
|
||
// queueReconnect queues a reconnection attempt. | ||
func (conn *wsConn) queueReconnect(wait time.Duration) { | ||
conn.setConnected(false) | ||
log.Infof("Attempting reconnect to %s in %d seconds.", conn.cfg.URL, wait/time.Second) | ||
time.AfterFunc(wait, func() { conn.reconnectCh <- struct{}{} }) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using these from outside read()
would be all kinds of problematic, so they are moved into read
.
err = conn.ws.WriteMessage(websocket.TextMessage, b) | ||
if err != nil { | ||
log.Errorf("write error: %v", err) | ||
log.Errorf("Send: WriteMessage error: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had briefly added a conn.close()
here to cause the read loop to error and trigger reconnect, but the write error itself seems to be enough to cause reads (e.g. ws.ReadJSON
) to return with an error immediately.
client/core: prevent swap bcast with stale dex conn more careful reconnect, remove max reconnects
ee89dbe
to
a542cb1
Compare
Swap contracts are no longer permitted to be broadcast if the DEX connection is known to be down. This can happen when a computer or client process comes out of suspend and immediately tries to take their action, particularly the taker trying to bcast their swap. The net connection's read timeout must still put the link into a failed state quickly for this to work during a resume, but this connectivity check is also valuable with normal connectivity trouble, not just machine/process suspend.
Triggering of ticks with the tick timer is also modified to skip tick execution if a long delay since the previous timer fire is detected (computer resume) to allow time for DEX re-connection. This together with the swap check described above prevents needlessly broadcasting a swap contract for a match that is revoked unbeknownst to the client. The swap check is still necessary however since asset tip changes also trigger a tick.
client/comms.WsConn reconnect logic is tweaked to prevent back-to-back or duplicate queued reconnect attempts. This is especially necessary now since send errors in Send and the ping handler now also trigger reconnect. Previously read errors would only trigger reconnect. The (*wsConn).read loop now detects and logs timeouts immediately before all other error checks to hasten flagging the connection as down and to log the timeout as the cause in plain language.