dash-extensions icon indicating copy to clipboard operation
dash-extensions copied to clipboard

Removing a Websocket Errors

Open Parker-Bergen opened this issue 3 years ago • 9 comments

Hi, I am currently rending a Websocket when I need to, but when I stop render the Websocket , remove it from children of an object, the Websocket will try to push its props back to the child resulting in an error since non of the object information about the Websocket component exists. Is there a way around this or to stop the Websocket from pushing its props on close? Children should be empty but instead gets filled with the below info: image_2022-04-25_170036973

Parker-Bergen avatar Apr 25 '22 21:04 Parker-Bergen

Could you provide a MWE in code?

emilhe avatar Apr 26 '22 05:04 emilhe

Below I have linked a basic server from your documentation and then the client server with the breaking websockets. I have added them as txts because .py is not allowed and I could not paste them nicely. Websocket Delete Example.txt Delete Example Server.txt

Parker-Bergen avatar May 02 '22 18:05 Parker-Bergen

For code, please use the markdown code blocks available in the editor by clicking the <> symbol. The easiest is typically to pasta a block of code, then highlight the code and click the <> symbol.

I just tried running your example, and I get the error. But it doesn't seem related to the websocket, the error seems related to bugs in the way children are being manipulated in the update_output_sockets callback.

emilhe avatar May 02 '22 20:05 emilhe

For some reason when I wrapped the code in the code block it excluded large parts of the code. In relation to the error, although it is a children problem, it is stemmed from when I remove the websocket child. The websocket disconnects and as a result the websocket tries to write its state to the previously existing websocket component, however that no longer exists and so it is just written in the children, but that set of info is not a component and so the dashboard errors. If there is a way to prevent this state from updating or checking if the component still exists before writing, I believe it would solve the issue as the component will not try and write its final death state.

Parker-Bergen avatar May 02 '22 21:05 Parker-Bergen

Hi, I suspect that I currently have the same problem using websockets in my dash project, so I wanted to know if there is any news on this? My scenario is that I have a dash app with multiple pages and I only want to keep a websocket connection open if the user is on one specific page. I can connect to the websocket on that specific page, but when I try to change the page (and thereby close and unload the websocket) the app crashes. I hope to hear any updates you might have. Thanks!

KristofferFogh04 avatar May 30 '22 10:05 KristofferFogh04

Hi, I have encountered the same issue when using a WebSocket in a multipage app and changing away from a page containing one ore more unclosed WebSockets. The full traceback is:

(This error originated from the built-in JavaScript code that runs Dash apps. Click to see the full stack trace or open your browser's console.)
TypeError: t.split is not a function

    at u.value (http://localhost:8050/_dash-component-suites/dash/dcc/async-markdown.js:2:5115)

    at u.value (http://localhost:8050/_dash-component-suites/dash/dcc/async-markdown.js:2:6646)

    at finishClassComponent (http://localhost:8050/_dash-component-suites/dash/deps/[email protected]_7_0m1669813432.14.0.js:17295:33)

    at updateClassComponent (http://localhost:8050/_dash-component-suites/dash/deps/[email protected]_7_0m1669813432.14.0.js:17245:26)

    at beginWork (http://localhost:8050/_dash-component-suites/dash/deps/[email protected]_7_0m1669813432.14.0.js:18755:18)

    at HTMLUnknownElement.callCallback (http://localhost:8050/_dash-component-suites/dash/deps/[email protected]_7_0m1669813432.14.0.js:182:16)

    at Object.invokeGuardedCallbackDev (http://localhost:8050/_dash-component-suites/dash/deps/[email protected]_7_0m1669813432.14.0.js:231:18)

    at invokeGuardedCallback (http://localhost:8050/_dash-component-suites/dash/deps/[email protected]_7_0m1669813432.14.0.js:286:33)

    at beginWork$1 (http://localhost:8050/_dash-component-suites/dash/deps/[email protected]_7_0m1669813432.14.0.js:23338:9)

    at performUnitOfWork (http://localhost:8050/_dash-component-suites/dash/deps/[email protected]_7_0m1669813432.14.0.js:22292:14)

emillma avatar Jan 18 '23 14:01 emillma

Hi, I also have this issue and it could probably be resolved exactly like @Parker-Bergen suggested... just remove the onclose callback before closing the connection inside componentWillUnmount():

https://github.com/thedirtyfew/dash-extensions/blob/master/src/lib/components/WebSocket.react.js#L78

PS: Actually, remove all callbacks here just to be safe and avoid memory leaks. ^^

m3g4p0p avatar Mar 03 '23 05:03 m3g4p0p

I have just pushed an rc release with a potential fix. Could you test if it resolves your issues @m3g4p0p ?

https://pypi.org/project/dash-extensions/0.1.14rc1/

emilhe avatar Mar 13 '23 13:03 emilhe

Hi @emilhe, yes cool many thanks, that seems to have fixed the issue. :)

m3g4p0p avatar Mar 14 '23 08:03 m3g4p0p