Skip to content

webAgg example broken - maybe mpl.js broken? #19129

Closed

Description

@ianhi

Bug report

Extracting the extra bug discovered in #19116 (comment)

Bug summary
The code in https://matplotlib.org/devdocs/gallery/user_interfaces/embedding_webagg_sgskip.html does not display anything in the browser when running master matplotlib (27aaf0c)

Code for reproduction

Actual outcome

No plot + this DOM exception in the JS console:

Uncaught DOMException: An attempt was made to use an object that is not, or is no longer, usable mpl.js:394
    send_message http://127.0.0.1:8080/mpl.js:394
    _init_canvas http://127.0.0.1:8080/mpl.js:161
    figure http://127.0.0.1:8080/mpl.js:55
    <anonymous> http://127.0.0.1:8080/:40

Expected outcome
A working interactive plot shows up

Matplotlib version

  • Operating system: Ubuntu 20.04
  • Matplotlib version: 27aaf0c
  • Matplotlib backend (print(matplotlib.get_backend())): webAgg
  • Python version: 3.9.0
  • Browser: Firefox 83.0

Installed python from conda-forge:

Python 3.9.0 | packaged by conda-forge | (default, Oct 14 2020, 22:59:50) 
[GCC 7.5.0] on linux

Activity

  1. QuLogic commented on Dec 16, 2020

    @QuLogic
    Member

    This is also broken as of v3.3.3, but I'm sure I tested this then due to backporting fixes for older Firefox. I wonder if this was a change in Firefox that broke it.

  2. tacaswell commented on Dec 16, 2020

    @tacaswell
    Member

    In chrome derivative on 3.3.3 I get a slightly better error:

    
    mpl.js:390 Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
        at mpl.figure.send_message (http://localhost:8080/mpl.js:390:13)
        at mpl.figure._init_canvas (http://localhost:8080/mpl.js:161:13)
        at new mpl.figure (http://localhost:8080/mpl.js:55:10)
        at HTMLDocument.<anonymous> (http://localhost:8080/:40:21)
    

    I also manually tested this in prep of 3.3.3 . Could the problem be on the other side and someting changed in tornado's websockets?

  3. QuLogic commented on Dec 16, 2020

    @QuLogic
    Member

    This bisects to #18361, which sends the pixel ratio message earlier (in _init_canvas); I suppose leaving it to the ws.onopen might be fine, but needs testing?

  4. tacaswell commented on Dec 16, 2020

    @tacaswell
    Member

    🐑

  5. tacaswell commented on Dec 16, 2020

    @tacaswell
    Member

    I did just verify that nbagg still works on v3.3.3 so that is good at least. Presumably we go through a slightly different song/dance to stand the js side figure up in the two cases?

  6. added a commit that references this issue on Dec 16, 2020
    30a900f
  7. QuLogic commented on Dec 16, 2020

    @QuLogic
    Member

    Yes, nbagg uses a proxy to a WebSocket from ipykernel, which I assume is already stood up before we get it.

  8. added this to the v3.3.4 milestone on Dec 17, 2020
  9. aathan commented on Jan 24, 2021

    @aathan

    I (independently) found and fixed this bug in the onopen() manner suggested above, so the fix is corroborated. This was in matplotlib 3.3.3 vs recent Firefox. Just to be explicitly clear, what I am saying is: Ttriggering the call to mpl.figure() (in all_figures*.html or single_figure*.html) via websocket.onopen() works.

    (see https://discourse.matplotlib.org/t/webagg-backend-js-bug-websocket-not-ready/21796)

    Looking at 30a900f which closed this problem it seems the fix was to not send pixelratio. However, that would not seem to me to address the root cause. The fact is that neither mpl.figure(), nor anything else, should use the websocket before it is open. As written, the possibility remains open that any future changes to mpl.figure() initialization will cause the issue to happen again.

    I believe the correct solution is to not initialize mpl.figure() until the socket is in fact ready -- or otherwise cause mpl.figure() to refrain from socket operations until we're sure it is open. The link above shows how I avoided the issue by calling mpl.figure() (in all_figures*.html) from websocket.onopen(). However, it did not occur to me that I may then have overriden the original onopen() behavior of that websocket. Possibly I need to also call the prior onopen()?

  10. QuLogic commented on Jan 28, 2021

    @QuLogic
    Member

    I suggest you open a pull request so we can review the change better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions