Bokeh server getting killed by memory leak, and sometimes also getting Getting an "extra unexpected referrers!" error

This is an extremely rare/uncommon message to see. I’m not sure I can recall any users ever reporting seeing it before. It’s probably worth a glance at the actual function that raises this error:

bokeh/document.py at branch-2.4 · bokeh/bokeh · GitHub

This function delete_modules is called whenever a Document is destroyed, e.g because a session is closed and cleaned up. The checks explicitly assert that the modules associated with the Document are only references in expected ways/places, so that they can be expected to be garbage collected. So, this message is saying that is not the case, and something somewhere is holding on to an unexpected reference (which could prevent garbage collection).

Things that could plausibly cause an extra reference:

  • Evidently get_referrers makes fairly loose guarantees. Are you using Python 3.10 or 3.11 preview? There is a very slight chance that Python itself has made some change here (that would only explain seeing a referrers message though, not an actual leak)

  • It’s possible Holoviews/Panel is somehow holding on to the app module in some way cc @Philipp_Rudiger

  • It’s possible Bokeh itself is holding on to a reference it should not (but I am not aware of any changes in this area in quite some time, and have not seen any other issues noted)

  • It’s possible that user code is holding the reference

For the last bullet, offhand the only thing that comes to mind is, say, creating a thread that outlives the session, and the code in the thread is holding on to something it shouldn’t. If your app code is creating threads then you would need to make sure clean up properly. But there are almost certainly other possibilities. As you say, it’s very difficult to speculate without an MRE (this would really take detailed investigation).

1 Like