savonet / liquidsoap

Liquidsoap is a statically typed scripting general-purpose language with dedicated operators and backend for all thing media, streaming, file generation, automation, HTTP backend and more.
http://liquidsoap.info
GNU General Public License v2.0
1.4k stars 128 forks source link

Harbor register on same port as existing harbor input/output causes: Address already in use in bind() #1726

Closed mcoms closed 2 years ago

mcoms commented 3 years ago

Describe the bug When you use a harbor register in the same script with the same port as a harbor input or output, the script exits with an error: Address already in use in bind()!

To Reproduce

set("harbor.bind_addrs", ["0.0.0.0"])
set("log.file", false)
set("log.stdout", true)

def test(~protocol, ~data, ~headers, uri) =
  http_response(protocol=protocol, code=200, data="Test")
end

harbor.http.register(port=8000, method="GET", "/test.txt", test)

output.harbor(%vorbis, port=8000, mount="test.ogg", sine())
liquidsoap_1  | 2021/07/05 21:53:03 >>> LOG START
liquidsoap_1  | 2021/07/05 21:53:03 [main:3] Liquidsoap 1.4.4
liquidsoap_1  | 2021/07/05 21:53:03 [main:3] Using: bytes=[distributed with OCaml 4.02 or above] pcre=7.4.6 sedlex=2.3 menhirLib=20201216 dtools=0.4.1 duppy=0.8.0 cry=0.6.4 mm=0.5.0 xmlplaylist=0.1.4 lastfm=0.3.2 ogg=0.5.2 vorbis=0.7.1 opus=0.1.3 speex=0.2.1 mad=0.4.6 flac=0.1.5 flac.ogg=0.1.5 dynlink=[distributed with Ocaml] lame=0.3.4 shine=0.2.1 gstreamer=0.3.0 frei0r=0.1.1 fdkaac=0.3.2 theora=0.3.1 ffmpeg=0.4.3 bjack=0.1.5 alsa=0.2.3 ao=0.2.1 samplerate=0.1.4 taglib=0.3.6 ssl=0.5.9 magic=0.7.3 camomile=1.0.2 inotify=2.3 yojson=1.7.0 faad=0.4.0 soundtouch=0.1.8 portaudio=0.2.1 pulseaudio=0.1.3 ladspa=0.1.5 dssi=0.1.2 camlimages=4.2.6 srt.types=0.1.1 srt.stubs=0.1.1 srt.stubs=0.1.1 srt=0.1.1 lo=0.1.2 gd=1.0a5
liquidsoap_1  | 2021/07/05 21:53:03 [gstreamer.loader:3] Loaded GStreamer 1.18.3 0
liquidsoap_1  | 2021/07/05 21:53:03 [harbor:3] Adding handler for 'GET /test.txt' on port 8000
liquidsoap_1  | 2021/07/05 21:53:03 [frame:3] Using 44100Hz audio, 25Hz video, 44100Hz master.
liquidsoap_1  | 2021/07/05 21:53:03 [frame:3] Frame size must be a multiple of 1764 ticks = 1764 audio samples = 1 video samples.
liquidsoap_1  | 2021/07/05 21:53:03 [frame:3] Targetting 'frame.duration': 0.04s = 1764 audio samples = 1764 ticks.
liquidsoap_1  | 2021/07/05 21:53:03 [frame:3] Frames last 0.04s = 1764 audio samples = 1 video samples = 1764 ticks.
liquidsoap_1  | 2021/07/05 21:53:03 [sandbox:3] Running inside a docker container, disabling sandboxing..
liquidsoap_1  | 2021/07/05 21:53:03 [video.converter:3] Couldn't find preferred video converter: gavl.
liquidsoap_1  | 2021/07/05 21:53:03 [audio.converter:3] Using samplerate converter: ffmpeg.
liquidsoap_1  | 2021/07/05 21:53:03 [clock.wallclock_main:2] Error when starting output test(dot)ogg: Address already in use in bind()!
liquidsoap_1  | Raised by primitive operation at file "harbor/harbor.ml", line 989, characters 6-30
liquidsoap_1  | Called from file "list.ml", line 92, characters 20-23
liquidsoap_1  | Called from file "harbor/harbor.ml", line 999, characters 31-69
liquidsoap_1  | Called from file "harbor/harbor.ml", line 1022, characters 19-44
liquidsoap_1  | Called from file "harbor/harbor.ml", line 1058, characters 18-45
liquidsoap_1  | Called from file "outputs/harbor_output.ml", line 601, characters 8-61
liquidsoap_1  | Called from file "tools/start_stop.ml", line 108, characters 8-18
liquidsoap_1  | Called from file "clock.ml", line 245, characters 20-38
liquidsoap_1  | 
liquidsoap_1  | 2021/07/05 21:53:03 [main:3] Shutdown started!
liquidsoap_1  | 2021/07/05 21:53:03 [main:3] Waiting for main threads to terminate...
liquidsoap_1  | 2021/07/05 21:53:03 [main:3] Threads terminated.
liquidsoap_1  | 2021/07/05 21:53:03 [threads:3] Shutting down scheduler...
liquidsoap_1  | 2021/07/05 21:53:03 [threads:3] Scheduler shut down.
liquidsoap_1  | 2021/07/05 21:53:03 [threads:3] Waiting for queue threads to terminate...
liquidsoap_1  | 2021/07/05 21:53:03 [threads:3] Queues shut down
liquidsoap_1  | 2021/07/05 21:53:03 [main:3] Cleaning downloaded files...
liquidsoap_1  | 2021/07/05 21:53:03 [main:3] Freeing memory...
liquidsoap_1  | 2021/07/05 21:53:03 >>> LOG END

Expected behavior The script to run and for both /test.txt and /test.ogg to be served on port 8000.

I got the idea this was possible from following along with the docs page which has this comment:

# Register this handler at port 8005
# (provided harbor sources are also served
#  from this port).
harbor.http.register(port=8005 ...

This made me think you could register new handlers on the same port as an existing harbour input/output.

Version details

toots commented 3 years ago

I can confirm the issue. output.harbor uses a different layer for handling its sockets than the regular harbor server, despite their common names.. I will see if we can merge them.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue was closed for lack of activity. If you believe that it is still relevant, please confirm that it applies to the latest released version of liquidsoap and re-open the ticket. Thanks!