signalfx / signalfx-go

Go client library and instrumentation bindings for SignalFx
https://www.signalfx.com
Apache License 2.0
14 stars 48 forks source link

Context cancellation handling #131

Closed nobl9-adam-szymanski closed 3 years ago

nobl9-adam-szymanski commented 3 years ago

According to documentation after Client.Close() is invoked, client should not be used anymore. This behavior is desired.

Close the client and shutdown any ongoing connections and go routines. The client cannot be reused after Close.

The problem is when connection is not ready and Client.Close() is invoked, context is canceled but reconnect tries indefinitely connect to the server without checking context status. There is no way to stop go routine.

Steps to reproduce:

  1. Create client with invalid realm.
  2. Close connection with client.Close().
    client, err = signalflow.NewClient(
    signalflow.StreamURLForRealm("foo"),
    signalflow.AccessToken(s.AccessToken),
    )
    client.Close()

Expected result:

  1. Context is cancelled, reconnecting stopped.
  2. Go routine is closed when context is canceled.

Actual result:

  1. Context is cancelled and go routine is running in the background indefinitely. Log printed every 5 seconds with message Error connecting to SignalFlow websocket: could not connect Signalflow websocket: dial tcp: operation was canceled
  2. There is now way to close this go routine outside the Client.