exokitxr / exokit

Native VR/AR/XR engine for JavaScript 🦖
MIT License
997 stars 117 forks source link

Websocket close is crashing Exokit #1386

Closed bknill closed 5 years ago

bknill commented 5 years ago

I'm using Redux and in the code base is the Redux enhancer which uses a websocket for debugging.

I've tried commenting it out with some success.. however this isn't ideal and if I try and test for Exokit before running it still tries to set up the Websocket connection, and crashes with this error:

uncaught exception: Error: WebSocket was closed before the connection was established
    at WebSocket.close (/home/owner/workspace/client/exokit/node_modules/ws/lib/websocket.js:217:14)
    at WebSocketTransport.push../node_modules/sockjs-client/lib/transport/websocket.js.WebSocketTransport.close (https://localhost:3000/static/js/7.chunk.js:478842:8)
    at SockJS.push../node_modules/sockjs-client/lib/main.js.SockJS._transportTimeout (https://localhost:3000/static/js/7.chunk.js:476435:23)
    at listOnTimeout (internal/timers.js:533:17)
    at processTimers (internal/timers.js:475:7)

This is deep in the Redux code, is there anyway to handle this in Exokit to stop the crash?

avaer commented 5 years ago

This looks like it's not Exokit crashing -- Exokit is catching the error.

This might be a bug in Exokit though, if this throw is non-standard behavior. I'll look into this. Thanks for filing!

avaer commented 5 years ago

Indeed, I think this should be a non-throwing case, but it throws in Exokit:

c = new WebSocket('ws://lol.com');
c.close();
avaer commented 5 years ago

@bknill Could you try https://github.com/exokitxr/exokit/pull/1388 to see if it handles this issue?

bknill commented 5 years ago

The error has changed but the crash appears to be more serious

core:a-node:error Failure loading node:   TypeError: ctx.setGrContext is not a function
    at _onGl2DConstruct (/home/owner/workspace/client/exokit/src/native-bindings.js:435:9)
    at new CanvasRenderingContext2D (/home/owner/workspace/client/exokit/src/native-bindings.js:456:5)
    at HTMLCanvasElement.getContext (/home/owner/workspace/client/exokit/src/DOM.js:2557:23)
    at setup (https://localhost:3000/static/js/7.chunk.js:64257:36)
    at NewComponent.init (https://localhost:3000/static/js/7.chunk.js:64229:13)
    at NewComponent.initComponent (https://localhost:3000/static/js/7.chunk.js:69876:16)
    at NewComponent.updateProperties (https://localhost:3000/static/js/7.chunk.js:69856:18)
    at HTMLElement.value (https://localhost:3000/static/js/7.chunk.js:68371:25)
    at HTMLElement.value (https://localhost:3000/static/js/7.chunk.js:71553:49)
    at HTMLElement.value (https://localhost:3000/static/js/7.chunk.js:68343:20)
    at entityLoadCallback (https://localhost:3000/static/js/7.chunk.js:68104:20)
    at emitLoaded (https://localhost:3000/static/js/7.chunk.js:69171:19)
    at runNextTicks (internal/process/task_queues.js:55:5)
    at processTimers (internal/timers.js:472:9)
Error: WebSocket was closed before the connection was established
    at WebSocket.close (/home/owner/workspace/client/exokit/node_modules/ws/lib/websocket.js:217:14)
    at WebSocket.close (/home/owner/workspace/client/exokit/src/WindowBase.js:184:24)
    at WebSocketTransport.push../node_modules/sockjs-client/lib/transport/websocket.js.WebSocketTransport.close (https://localhost:3000/static/js/7.chunk.js:478867:8)
    at SockJS.push../node_modules/sockjs-client/lib/main.js.SockJS._transportTimeout (https://localhost:3000/static/js/7.chunk.js:476460:23)
    at listOnTimeout (internal/timers.js:533:17)
    at processTimers (internal/timers.js:475:7)
avaer commented 5 years ago

Thanks, that looks like progress. I can't tell from this why the Canvas2D would be uninitialized however.

Are you able to console.log(ctx) on this line? https://github.com/exokitxr/exokit/blob/b352ee0fedb6afa19fe71db9a9c584a94e6e165b/src/native-bindings.js#L434

bknill commented 5 years ago

Do I need to rebuild exokit with this change?

avaer commented 5 years ago

If it's on Linux then no rebuild needed, it should just be a JS file change. 👍

bknill commented 5 years ago

Its not even starting at the moment.

unhandled rejection: TypeError: nativeWindow.hasCurrentWindowContext is not a function
    at _waitLocalSyncs (/home/owner/workspace/client/exokit/src/Window.js:1037:24)
    at Array._renderLocal (/home/owner/workspace/client/exokit/src/Window.js:1156:13)
    at _recurse (/home/owner/workspace/client/exokit/src/Window.js:1171:19)
    at /home/owner/workspace/client/exokit/src/Window.js:1185:5
    at new Promise (<anonymous>)
    at _render (/home/owner/workspace/client/exokit/src/Window.js:1167:39)
    at window.tickAnimationFrame (/home/owner/workspace/client/exokit/src/Window.js:1191:12)
    at global.onrunasync (/home/owner/workspace/client/exokit/src/Window.js:1351:21)
    at MessagePort.<anonymous> (/home/owner/workspace/client/exokit/src/WindowBase.js:320:45)
    at MessagePort.emit (events.js:196:13)
bknill commented 5 years ago

Took that console log out and get this far:

ore:a-node:error Failure loading node:   TypeError: ctx.setGrContext is not a function
    at _onGl2DConstruct (/home/owner/workspace/client/exokit/src/native-bindings.js:436:9)
    at new CanvasRenderingContext2D (/home/owner/workspace/client/exokit/src/native-bindings.js:457:5)
    at HTMLCanvasElement.getContext (/home/owner/workspace/client/exokit/src/DOM.js:2557:23)
    at NewShader.init (https://localhost:3000/static/js/4.chunk.js:883:31)
    at NewComponent.updateShader (https://localhost:3000/static/js/4.chunk.js:62334:26)
    at NewComponent.update (https://localhost:3000/static/js/4.chunk.js:62258:18)
    at NewComponent.initComponent (https://localhost:3000/static/js/4.chunk.js:69884:16)
    at NewComponent.updateProperties (https://localhost:3000/static/js/4.chunk.js:69856:18)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68371:25)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68343:20)
    at entityLoadCallback (https://localhost:3000/static/js/4.chunk.js:68104:20)
    at emitLoaded (https://localhost:3000/static/js/4.chunk.js:69171:19)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
core:a-node:error Failure loading node:   TypeError: ctx.setGrContext is not a function
    at _onGl2DConstruct (/home/owner/workspace/client/exokit/src/native-bindings.js:436:9)
    at new CanvasRenderingContext2D (/home/owner/workspace/client/exokit/src/native-bindings.js:457:5)
    at HTMLCanvasElement.getContext (/home/owner/workspace/client/exokit/src/DOM.js:2557:23)
    at NewShader.init (https://localhost:3000/static/js/4.chunk.js:883:31)
    at NewComponent.updateShader (https://localhost:3000/static/js/4.chunk.js:62334:26)
    at NewComponent.update (https://localhost:3000/static/js/4.chunk.js:62258:18)
    at NewComponent.initComponent (https://localhost:3000/static/js/4.chunk.js:69884:16)
    at NewComponent.updateProperties (https://localhost:3000/static/js/4.chunk.js:69856:18)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68371:25)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68343:20)
    at entityLoadCallback (https://localhost:3000/static/js/4.chunk.js:68104:20)
    at emitLoaded (https://localhost:3000/static/js/4.chunk.js:69171:19)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
core:a-node:error Failure loading node:   TypeError: ctx.setGrContext is not a function
    at _onGl2DConstruct (/home/owner/workspace/client/exokit/src/native-bindings.js:436:9)
    at new CanvasRenderingContext2D (/home/owner/workspace/client/exokit/src/native-bindings.js:457:5)
    at HTMLCanvasElement.getContext (/home/owner/workspace/client/exokit/src/DOM.js:2557:23)
    at NewShader.init (https://localhost:3000/static/js/4.chunk.js:883:31)
    at NewComponent.updateShader (https://localhost:3000/static/js/4.chunk.js:62334:26)
    at NewComponent.update (https://localhost:3000/static/js/4.chunk.js:62258:18)
    at NewComponent.initComponent (https://localhost:3000/static/js/4.chunk.js:69884:16)
    at NewComponent.updateProperties (https://localhost:3000/static/js/4.chunk.js:69856:18)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68371:25)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68343:20)
    at entityLoadCallback (https://localhost:3000/static/js/4.chunk.js:68104:20)
    at emitLoaded (https://localhost:3000/static/js/4.chunk.js:69171:19)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
core:a-node:error Failure loading node:   TypeError: ctx.setGrContext is not a function
    at _onGl2DConstruct (/home/owner/workspace/client/exokit/src/native-bindings.js:436:9)
    at new CanvasRenderingContext2D (/home/owner/workspace/client/exokit/src/native-bindings.js:457:5)
    at HTMLCanvasElement.getContext (/home/owner/workspace/client/exokit/src/DOM.js:2557:23)
    at NewShader.init (https://localhost:3000/static/js/4.chunk.js:883:31)
    at NewComponent.updateShader (https://localhost:3000/static/js/4.chunk.js:62334:26)
    at NewComponent.update (https://localhost:3000/static/js/4.chunk.js:62258:18)
    at NewComponent.initComponent (https://localhost:3000/static/js/4.chunk.js:69884:16)
    at NewComponent.updateProperties (https://localhost:3000/static/js/4.chunk.js:69856:18)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68371:25)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68343:20)
    at entityLoadCallback (https://localhost:3000/static/js/4.chunk.js:68104:20)
    at emitLoaded (https://localhost:3000/static/js/4.chunk.js:69171:19)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
core:a-node:error Failure loading node:   TypeError: ctx.setGrContext is not a function
    at _onGl2DConstruct (/home/owner/workspace/client/exokit/src/native-bindings.js:436:9)
    at new CanvasRenderingContext2D (/home/owner/workspace/client/exokit/src/native-bindings.js:457:5)
    at HTMLCanvasElement.getContext (/home/owner/workspace/client/exokit/src/DOM.js:2557:23)
    at NewShader.init (https://localhost:3000/static/js/4.chunk.js:883:31)
    at NewComponent.updateShader (https://localhost:3000/static/js/4.chunk.js:62334:26)
    at NewComponent.update (https://localhost:3000/static/js/4.chunk.js:62258:18)
    at NewComponent.initComponent (https://localhost:3000/static/js/4.chunk.js:69884:16)
    at NewComponent.updateProperties (https://localhost:3000/static/js/4.chunk.js:69856:18)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68371:25)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68343:20)
    at entityLoadCallback (https://localhost:3000/static/js/4.chunk.js:68104:20)
    at emitLoaded (https://localhost:3000/static/js/4.chunk.js:69171:19)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
core:a-node:error Failure loading node:   TypeError: ctx.setGrContext is not a function
    at _onGl2DConstruct (/home/owner/workspace/client/exokit/src/native-bindings.js:436:9)
    at new CanvasRenderingContext2D (/home/owner/workspace/client/exokit/src/native-bindings.js:457:5)
    at HTMLCanvasElement.getContext (/home/owner/workspace/client/exokit/src/DOM.js:2557:23)
    at NewShader.init (https://localhost:3000/static/js/4.chunk.js:883:31)
    at NewComponent.updateShader (https://localhost:3000/static/js/4.chunk.js:62334:26)
    at NewComponent.update (https://localhost:3000/static/js/4.chunk.js:62258:18)
    at NewComponent.initComponent (https://localhost:3000/static/js/4.chunk.js:69884:16)
    at NewComponent.updateProperties (https://localhost:3000/static/js/4.chunk.js:69856:18)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68371:25)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68343:20)
    at entityLoadCallback (https://localhost:3000/static/js/4.chunk.js:68104:20)
    at emitLoaded (https://localhost:3000/static/js/4.chunk.js:69171:19)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
THREE.Box3: .getSize() target is now required
THREE.Box3: .getSize() target is now required
core:a-node:error Failure loading node:   TypeError: ctx.setGrContext is not a function
    at _onGl2DConstruct (/home/owner/workspace/client/exokit/src/native-bindings.js:436:9)
    at new CanvasRenderingContext2D (/home/owner/workspace/client/exokit/src/native-bindings.js:457:5)
    at HTMLCanvasElement.getContext (/home/owner/workspace/client/exokit/src/DOM.js:2557:23)
    at setup (https://localhost:3000/static/js/4.chunk.js:64257:36)
    at NewComponent.init (https://localhost:3000/static/js/4.chunk.js:64229:13)
    at NewComponent.initComponent (https://localhost:3000/static/js/4.chunk.js:69876:16)
    at NewComponent.updateProperties (https://localhost:3000/static/js/4.chunk.js:69856:18)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68371:25)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:71553:49)
    at HTMLElement.value (https://localhost:3000/static/js/4.chunk.js:68343:20)
    at entityLoadCallback (https://localhost:3000/static/js/4.chunk.js:68104:20)
    at emitLoaded (https://localhost:3000/static/js/4.chunk.js:69171:19)
bknill commented 5 years ago

Switched back to master and everything is running fine. That websocket error only seems to happen intermitently.

avaer commented 5 years ago

Switched back to master and everything is running fine.

Which branch was being run before?

avaer commented 5 years ago

Was this one with the console.log? https://github.com/exokitxr/exokit/issues/1386#issuecomment-519319188

The log I would have expected to see was the CanvasRenderingContext2D.

bknill commented 5 years ago

No it failed when it tried to console.log(ctx)