vbmithr / ocaml-websocket

Websocket library for OCaml
ISC License
161 stars 44 forks source link

End_of_file exception when doing `send` #92

Open alinpopa opened 7 years ago

alinpopa commented 7 years ago

I'm trying to do something like this, just before this line: https://github.com/vbmithr/ocaml-websocket/blob/master/lwt/wscat.ml#L27

...
let _ = send @@ Frame.create ~content:"some stuff here" () in
Lwt_io.printf "> %s\n> %!" fr.content
... 

and I'm getting an End_of_file exception; wasn't able to find anything within the documentation, or the code, that would help me to prevent that... What I'm trying to do, in fact, is to have a periodic sender, that once at, let's say 10 seconds, will send some message to the server, and I imagine that send is used for that. Any idea what am I missing here?

Thanks.

vbmithr commented 7 years ago

Le 20/06/2017 à 14:29, Alin Popa a écrit :

Any idea what am I missing here?

Can you give me an example program that I can use to reproduce this issue?

Thanks,

-- Vincent

alinpopa commented 7 years ago

Sure; although the context here is quite complex: implementing a Slack client, that does various things, and one of them is to make sure the connection is up and running (yeah, I could use the pinging mechanism that the Websocket_lwt is providing, but I wanted to be able to explicitly send Slack ping messages); This is the line that makes it fail: https://github.com/alinpopa/mlvin/blob/lwt_test_send/src/lwt/slack_lwt.ml#L70

In order to build it, you'll need to do:

make lwt

then, to run it, you'll need a Slack token (don't worry about this one, will delete it after you've looked at it :) ):

 ./_build/default/bin/lwt/main.exe -t xoxb-201853301687-hr88hLxuogqiTIKE2X5AsVlC

so, I'm getting the following issue:

Jun 21 06:34:47.546 [info] Restarting ...
Jun 21 06:34:47.894 [info] Connected to https://mpmulti-6g61.slack-msgs.com/websocket/gaEWxQ6UJlb9MIlly98yNDSUVrfP0tGWHGTPcxAQuuBRZtmoQRvgoBJFO5a_zNu_iqYmRKe-AYBl2YYdWnmjp64GDjoODCAGEZ8qTxbAVgp2-CKpp9OQ1D2LMpjPgJpvBkvqFdtXb7XjWTShykft_NBI_OsAlOWHw86UVlTPQxg=
Jun 21 06:34:48.173 [info] LINE: {"type":"hello"}
Jun 21 06:34:48.174 [info] LINE: {"type":"reconnect_url","url":"wss://mpmulti-vap6.slack-msgs.com/websocket/vvveNy4tymXw7E_kfyYtZaTCrNoaHCpAgd6Z4z3Woe5fR-9sM4Q0Zc2lEQ4q-dUQpCq6cKsACeMeoO2ZNxZcDce9k8LpebHWC4e-QLj_va97XFY0B7R2j_T01y6r_sAaOPyOoVce7RIzW1iJNfz7H8-Ezjb7Ta8KpIfz5aVlDeQ="}
Jun 21 06:34:48.276 [error] ERROR: End_of_file
Jun 21 06:34:48.276 [info] LINE: {"type":"pong","reply_to":1001}
Jun 21 06:34:48.276 [info] LINE: {}

If removing the send @@ Frame.create ... line, everything is working fine; Initially I was planning of adding a periodic timer that will do that send @@ Frame.create ..., and that's how I noticed the issue.

Thanks.

vbmithr commented 7 years ago

Ok, cannot repro the issue (programs runs fine). But I'm using bleeding edge versions of tons of libs, here is my makefile line: jbuilder build -p ipaddr,conduit,conduit-lwt,conduit-lwt-unix,cohttp,cohttp-lwt,cohttp-lwt-unix,websocket,websocket-lwt,mlvin,mlvin-lwt @install.

The code I tested is a slightly modified version of yours: http://github.com/vbmithr/mlvin#lwt_test_send

alinpopa commented 7 years ago

And what's happening when you add a let _ = send @@ Frame.create ~content:"blah" () in, right before this line https://github.com/vbmithr/mlvin/blob/master/src/lwt/slack_lwt.ml#L45 ?

alinpopa commented 7 years ago

I'll try with the bleeding edge repo, and see if I can reproduce the issue using your fork; thanks.

alinpopa commented 7 years ago

Ok, getting all sort of errors when installing conduit against janestreet's bleeding edge repo...

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫
[ERROR] The compilation of conduit failed at "make".
Processing  1/2: [conduit: ocamlfind remove]
#=== ERROR while installing conduit.0.15.4 ====================================#
# opam-version 1.2.2
# os           darwin
# command      make
# path         /Users/alin/.opam/mlvin-4.04.1-bleeding/build/conduit.0.15.4
# compiler     4.04.1
# exit-code    2
# env-file     /Users/alin/.opam/mlvin-4.04.1-bleeding/build/conduit.0.15.4/conduit-5664-6d07ae.env
# stdout-file  /Users/alin/.opam/mlvin-4.04.1-bleeding/build/conduit.0.15.4/conduit-5664-6d07ae.out
# stderr-file  /Users/alin/.opam/mlvin-4.04.1-bleeding/build/conduit.0.15.4/conduit-5664-6d07ae.err
### stdout ###
# ocamlbuild -use-ocamlfind -classic-display -cflags "-w A-4-33-40-41-42-43-34-44" -plugin-tag "package(ppx_driver.ocamlbuild)" conduit.otarget
# ocamlfind ocamlopt -package unix -package ocamlbuild -linkpkg -package ppx_driver.ocamlbuild myocamlbuild.ml /Users/alin/.opam/mlvin-4.04.1-bleeding/lib/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
# + ocamlfind ocamlopt -package unix -package ocamlbuild -linkpkg -package ppx_driver.ocamlbuild myocamlbuild.ml /Users/alin/.opam/mlvin-4.04.1-bleeding/lib/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
# ocamlfind: Package `ppx_driver.ocamlbuild' not found
# Command exited with code 2.
### stderr ###
# make: *** [all] Error 10
vbmithr commented 7 years ago

You need to put all the projects I mentioned in my Makefile line in the same directory and have jbuilder build all of them simultaneously!

Otherwise, I can repro your bug. I have the impression that the error is due to Slack closing the connection immediately after receiving the frame.

Do you see the "reconnect_url" line that slack sends? Don't you think you have to reconnect at this URL once you get this message? Not sure about it… but you may try.

alinpopa commented 7 years ago

I was also thinking the same thing, that might be a Slack issue, on how Slack does all the things behind the scene; regarding the reconnect_url, that's an experimental type of message, so definitely not the thing I'm doing wrong. Anyway, thanks for you help; feel free to close this issue, it was opened more as a curiosity that I might be doing something wrong.