holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.78k stars 519 forks source link

Unable to serve template panel on port other than 5006 #6498

Closed gwynforthewyn closed 8 months ago

gwynforthewyn commented 8 months ago

Thanks for contacting us! Please read and follow these instructions carefully, then delete this introductory text to keep your issue easy to read. Note that the issue tracker is NOT the place for usage questions and technical assistance; post those at Discourse instead. Issues without the required information below may be closed immediately.

ALL software version info

macos 14.3.1, running on a Macbook Pro with Apple M1 Pro.

requirements.txt:

panel==1.3.8
pandas
numpy
hvplot

a pip freeze shows:

bleach==6.1.0
bokeh==3.3.4
certifi==2024.2.2
charset-normalizer==3.3.2
colorcet==3.1.0
contourpy==1.2.0
holoviews==1.18.3
hvplot==0.9.2
idna==3.6
Jinja2==3.1.3
linkify-it-py==2.0.3
Markdown==3.6
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdit-py-plugins==0.4.0
mdurl==0.1.2
numpy==1.26.4
packaging==24.0
pandas==2.2.1
panel==1.3.8
param==2.0.2
pillow==10.2.0
python-dateutil==2.9.0.post0
pytz==2024.1
pyviz_comms==3.0.1
PyYAML==6.0.1
requests==2.31.0
six==1.16.0
tornado==6.4
tqdm==4.66.2
typing_extensions==4.10.0
tzdata==2024.1
uc-micro-py==1.0.3
urllib3==2.2.1
webencodings==0.5.1
xyzservices==2023.10.1

Description of expected behavior and the observed behavior

I built a simple panel app with template.Servable(). I initially ran it on the default port 5006, and it ran correctly. Then I tried to override the port to 8080, and the application broke with a websocket timeout error. I expected the changed port to make no difference to whether the app was served or not.

When I ran it with the defaults and it worked, I ran it like this:

panel serve simplepanel.py

I visited http://localhost:5006/ and was correctly served the app.

Then I tried several methods to switch to port 8080. I started with this:

panel serve --port 8080 simplepanel.py

I visited http://localhost:8080 and the app was not served; I received a socket timeout in my web browser.

I also tried these variants:

panel serve --port 8080 --allow-websocket-origin=localhost:8080 simplepanel.py

export BOKEH_ALLOW_WS_ORIGIN=localhost:8080
panel serve --port 8080 --allow-websocket-origin=localhost:8080 simplepanel.py

Note that the above combination of BOKEH_ALLOW_WS_ORIGIN and the 2 CLI parameters worked correctly on Panel version 0.13.1.

Each time I receive a socket timeout in my web browser that looks like this:

bokeh] Failed to load Bokeh session BZksDE0DdGilt6wIxOeaUQffZ71ApCHkaWoOpV4pEhIh: Error: Lost websocket connection, 1006 () [bokeh.min.js:225:671](http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b)
[bokeh] Failed to repull session Disconnected [bokeh.min.js:226:3322](http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b)

FWIW, the Bokeh docs at https://docs.bokeh.org/en/latest/docs/reference/settings.html#allowed-ws-origin do still list BOKEH_ALLOW_WS_ORIGIN

Complete, minimal, self-contained example code that reproduces the issue

import panel as pn
import numpy as np
import holoviews as hv

pn.extension()

# Define the function to create the plot
def sine_wave(phase=0, freq=1):
    xs = np.linspace(0, np.pi*4, 200)
    ys = np.sin(xs * freq + phase)
    return hv.Curve((xs, ys), 'x', 'y').opts(width=400, height=200, line_width=2)

# Create interactive components
phase_slider = pn.widgets.FloatSlider(name='Phase', start=0, end=np.pi*2, step=0.1, value=0)
freq_slider = pn.widgets.FloatSlider(name='Frequency', start=0.1, end=2, step=0.1, value=1)

@pn.depends(phase=phase_slider.param.value, freq=freq_slider.param.value)
def get_plot(phase, freq):
    return sine_wave(phase, freq)

# Create a Panel layout
layout = pn.Column(
    "# Sine Wave Generator",
    pn.Row(phase_slider, freq_slider),
    get_plot
)

# Use a basic template and add the layout to it
template = pn.template.FastListTemplate(
    title='Sine Wave App',
    main=[layout]
)

# Make the app servable
template.servable()

Stack traceback and/or browser JavaScript console output

There is no panel traceback. This is the browser console output:

GET
http://localhost:8080/simplepanel
[HTTP/1.1 200 OK 5750ms]

GET
http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b
[HTTP/1.1 200 OK 17ms]

GET
http://localhost:8080/static/js/bokeh-gl.min.js?v=6721b980580fb8317f83927f85b92aea8fec9bcd94ff58f895f85e5617987ee82f89b5da322b9cdb482c46ac2bd3442466f7ce2484bae8b414318a7ace09e901
[HTTP/1.1 200 OK 20ms]

GET
http://localhost:8080/static/js/bokeh-widgets.min.js?v=31de1843fe9e438f1829e492effd36329ababde542605297701ad7d96d2fc86464984340ba7645878652d1dccf43f535033e4cc55a45008c5bba7c20ae4577b9
[HTTP/1.1 200 OK 21ms]

GET
http://localhost:8080/static/js/bokeh-tables.min.js?v=755762f1b7b2263c503b8b87d5b02c242930ea7020b58deba3f8a9850aeeb96f21cd9c73e8ba792fce5be3489a32a4e3b852fe9eef1b3915ca60b08e349fe2fd
[HTTP/1.1 200 OK 20ms]

GET
http://localhost:8080/static/extensions/panel/panel.min.js?v=4dc754e770a2aaf1bd357f00e2c1ffb347b27f3b739a37791169825d30b0a501
[HTTP/1.1 200 OK 73ms]

GET
https://fonts.googleapis.com/css?family=Open+Sans
[HTTP/2 200  295ms]

GET
http://localhost:8080/static/extensions/panel/bundled/theme/default.css
[HTTP/1.1 200 OK 22ms]

GET
http://localhost:8080/static/extensions/panel/bundled/fastbasetemplate/fast.css
[HTTP/1.1 200 OK 21ms]

GET
http://localhost:8080/static/extensions/panel/bundled/fastlisttemplate/fast_list_template.css
[HTTP/1.1 200 OK 196ms]

GET
http://fonts.googleapis.com/css?family=Open+Sans
[HTTP/1.1 200 OK 186ms]

GET
http://localhost:8080/static/extensions/panel/bundled/fastbasetemplate/fast_template.js
[HTTP/1.1 200 OK 69ms]

GET
http://localhost:8080/static/extensions/panel/bundled/@microsoft/fast-components@2.30.6/dist/fast-components.js
[HTTP/1.1 200 OK 188ms]

GET
http://localhost:8080/static/extensions/panel/bundled/fast/js/fast_design.js
[HTTP/1.1 200 OK 191ms]

[bokeh] setting log level to: 'info' [bokeh.min.js:184:1311](http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b)
GET
http://fonts.gstatic.com/l/font?kit=memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsjZ0B4gaVQUwaEQbjA&skey=62c1cbfccc78b4b2&v=v40
[HTTP/1.1 200 OK 238ms]

GET
ws://localhost:8080/simplepanel/ws
[HTTP/1.1 101 Switching Protocols 3ms]

[bokeh] Websocket connection 0 is now open [bokeh.min.js:226:3416](http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b)
[bokeh] Lost websocket 0 connection, 1006 () [bokeh.min.js:226:3865](http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b)
[bokeh] Failed to load Bokeh session BZksDE0DdGilt6wIxOeaUQffZ71ApCHkaWoOpV4pEhIh: Error: Lost websocket connection, 1006 () [bokeh.min.js:225:671](http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b)
console.trace() Disconnected [bokeh.min.js:226:3304](http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b)
    _repull_session_doc http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    _awaiting_ack_handler http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    _current_handler http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    _on_message http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    onmessage http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    (Async: EventHandlerNonNull)
    connect http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    connect http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    pull_session http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    d http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:225
    add_document_from_session http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:225
    k http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:163
    embed_items http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:163
    embed_document http://localhost:8080/simplepanel:188
    fn http://localhost:8080/simplepanel:191
    fn http://localhost:8080/simplepanel:207
    safely http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:234
    fn http://localhost:8080/simplepanel:183
    (Async: EventListener.handleEvent)
    <anonymous> http://localhost:8080/simplepanel:211
    <anonymous> http://localhost:8080/simplepanel:212
[bokeh] Failed to repull session Disconnected [bokeh.min.js:226:3322](http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b)
Error rendering Bokeh items: Error: Lost websocket connection, 1006 ()
    _on_close http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    onclose http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    connect http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    connect http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    pull_session http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:226
    d http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:225
    add_document_from_session http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:225
    k http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:163
    embed_items http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:163
    embed_document http://localhost:8080/simplepanel:188
    fn http://localhost:8080/simplepanel:191
    fn http://localhost:8080/simplepanel:207
    safely http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b:234
    fn http://localhost:8080/simplepanel:183
    EventListener.handleEvent* http://localhost:8080/simplepanel:211
    <anonymous> http://localhost:8080/simplepanel:212
[bokeh.min.js:163:978](http://localhost:8080/static/js/bokeh.min.js?v=15dc4235f19f49742da0da503e059b08fd36649cd0c5a3e570cb2d53c86393c9b8ede7d19c9e3ab6da35adec3869a0b95f1a8d48fa2a7ebc6a45c69113c8829b)

Screenshots or screencasts of the bug in action

gwynforthewyn commented 8 months ago

One of my colleagues just sent me this note:

I just grepped the codebase a bit and it appears to be creating the websocket url from the DEFAULT_SERVER_URL const, rather than from what the server URL is actually determined to be after command line and env var interpolation

We are, of course, not super familiar with this codebase but he's a sharp dude and so I thought I should pass it forwards.

philippjfr commented 8 months ago

Thanks for the report. I'll have to dig into this a little bit but note that this would be extremely surprising, Panel apps are deployed in many forms on many different ports every day so if there was a regression here it would have definitely been caught by now.

philippjfr commented 8 months ago

One quick question is why you are even setting the allowable websocket origin when you're just serving on localhost. Is this just you doing testing for an actual deployment?

philippjfr commented 8 months ago

Skimmed over your question too quickly, sounds like you tried without it and that failed too. Do other ports work? I have no issues with port 8080 but I can imagine that it might be reserved for something on your system.

gwynforthewyn commented 8 months ago

I really appreciate the response, thank you! tl;dr I came home and can't reproduce it on my personal laptop; I'll see what I can figure out in the morning, but this looks like a bad report, sorry.

Before I had filed this issue, I was experiencing it with a couple of different applications. I asked one of my colleagues at work about it, and he tried upgrading a panel app from 0.13.1 to the latest version; he didn't experience the problem before the upgrade, but as soon as he had upgraded the issue was there for him too.

I'll close this and let's assume that we both had an orphaned container or something that was binding to port 8080; if we can still reproduce it, though, on separate hardware and separate networks tomorrow then I'll try and track down more specifics.

Thanks, once again