Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Cannot set property 'onopen' of null #808

Closed
ghost opened this issue Sep 28, 2020 · 9 comments
Closed

Cannot set property 'onopen' of null #808

ghost opened this issue Sep 28, 2020 · 9 comments

Comments

@ghost
Copy link

ghost commented Sep 28, 2020

Hi,

We started receiving Cannot set property 'onopen' of null errors in sentry after upgrading subscriptions-transport-ws to v0.9.18

A quick search sent me to this PR with 2 people discussing the issue: #615 (comment)

This error occurs only a few times a day so it is hard to create a reproduction repo, I have not looked deeply into it for now so I don't know if the suggested fix by @dko-slapdash would work.

I am not very familiar with the subscriptions-transport-ws, could someone look into it ?

Any help would we greatly appreciated :)

deps:

@atdrago
Copy link

atdrago commented Nov 12, 2020

I'm seeing this as well. Dev tools pointed me here:

image

It looks like this.client.onopen is being referenced after this.client.close() is called. I'm new to the code, but it looks like close sets this.client to null, hence the issue.

Downgrading to 0.9.16 seems to have fixed the issue for me

@D34THWINGS
Copy link

Same issue here, this started to cause issues in our application E2E tests. When changing page it kills the connection and Cypress catches all uncaught errors thrown on the window it makes our test fail. Downgrading also worked for us. I guess also having client: any makes the type-checking allowing those operations where they shouldn't be. Maybe defining client as a generic type that extends the browser basic implementation would be safer in the code. And also having a cleanup function with all this.client.onXXX = null in it after checking if client is still there.

One thing that is also super weird in the code is that this.client.onclose calls this.close which then calls this.client.close() which in turn this.client.onclose looping up which I wonder how it successfully escapes from this 🤔

But also might be interesting to look inside WsLink if any cleanup function doesn't do redundant WS closing causing this.

@yosiawan
Copy link

Same issue here, downgrading to 0.9.16 seemed to fixed it as @atdrago said, so 0.9.18 is probably broken.

@ghost
Copy link
Author

ghost commented Jan 22, 2021

Any idea on when #829 could be merged?

@ibash
Copy link

ibash commented Jan 26, 2021

@alexandre-kairn recommend using https://github.com/ds300/patch-package with a patch like:

diff --git a/node_modules/subscriptions-transport-ws/dist/client.js b/node_modules/subscriptions-transport-ws/dist/client.js
index 3202dcd..9f4b1ed 100644
--- a/node_modules/subscriptions-transport-ws/dist/client.js
+++ b/node_modules/subscriptions-transport-ws/dist/client.js
@@ -122,12 +122,13 @@ var SubscriptionClient = (function () {
                 this.unsubscribeAll();
                 this.sendMessage(undefined, message_types_1.default.GQL_CONNECTION_TERMINATE, null);
             }
-            this.client.close();
-            this.client.onopen = null;
-            this.client.onclose = null;
-            this.client.onerror = null;
-            this.client.onmessage = null;
+            const client = this.client;
             this.client = null;
+            client.close();
+            client.onopen = null;
+            client.onclose = null;
+            client.onerror = null;
+            client.onmessage = null;
             this.eventEmitter.emit('disconnected');
             if (!isForced) {
                 this.tryReconnect();

@ghost
Copy link
Author

ghost commented Jan 26, 2021

@ibash Thanks, indeed we went with something along those lines 👍

I was hoping to remove the patch when a new version is released, but at least this fixes the issue for now.

@vieira
Copy link

vieira commented Mar 31, 2021

We are also experiencing this issue.

Screen Shot 2021-03-31 at 11 13 08

@krhubert
Copy link

Same here, there's a lot of users affected to this error
image

Any ETA for the patch?

@glasser
Copy link
Member

glasser commented Jul 12, 2021

subscriptions-transport-ws is not currently actively maintained.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants