Skip to content

Close subscription client gracefully #399

@benjasper

Description

@benjasper

Describe the bug
When checking the error of the .Close() method it's always failed to unsubscribe: websocket: close sent because the connection seems to be already closed. This seems to be bad, as it doesn't really close the client.

To Reproduce
When checking the err in the tests, the tests fail:

diff --git a/internal/integration/integration_test.go b/internal/integration/integration_test.go
index 042c20f..789d50c 100644
--- a/internal/integration/integration_test.go
+++ b/internal/integration/integration_test.go
@@ -104,7 +104,10 @@ func TestSubscription(t *testing.T) {
 
 			dataChan, subscriptionID, err := count(ctx, wsClient)
 			require.NoError(t, err)
-			defer wsClient.Close()
+			defer func() {
+				err := wsClient.Close()
+				require.NoError(t, err)
+			}()
 
 			var (
 				counter = 0
@@ -198,7 +201,10 @@ func TestSubscriptionConnectionParams(t *testing.T) {
 
 			dataChan, subscriptionID, err := countAuthorized(ctx, wsClient)
 			require.NoError(t, err)
-			defer wsClient.Close()
+			defer func() {
+				err := wsClient.Close()
+				require.NoError(t, err)
+			}()
 
 			var (
 				counter = 0

Expected behavior
The tests should pass with the change above. And the client should be closed even if the connection was already closed.

genqlient version
Latest main

Additional context
If you like I can provide a PR, just let me know in which direction we should go. Ignore the error and close up things anyway or something else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions