janet-lang / spork

Various Janet utility modules - the official "Contrib" library.
MIT License
124 stars 36 forks source link

janet-netrepl -l VALUE and near-immediate client disconnection #160

Closed sogaiu closed 10 months ago

sogaiu commented 11 months ago

When trying the --library / -l functionality of janet-netrepl:

 -l, --library VALUE                         Load libraries in the repl as with the janet -l flag

I noticed that specifying something for VALUE that lives under JANET_PATH leads to a client connection being ended right after successful establishment.

The following is a demo.


Suppose spork is installed (so spork lives under JANET_PATH and janet-netrepl is available).

Start server:

$ janet-netrepl -l spork
Starting networked repl server on 127.0.0.1, port 9365...

Start client (note the exiting apparent from the second prompt):

$ janet-netrepl -c
$

Observe output for server:

client [127.0.0.1:9365] connected
closing client [127.0.0.1:9365]

Some investigation revealed that (dyn :syspath)'s value was nil within the handler function for spork/netrepl.janet's server function.

The following diff seemed to yield better results here:

diff --git a/spork/netrepl.janet b/spork/netrepl.janet
index 2556bf5..1986183 100644
--- a/spork/netrepl.janet
+++ b/spork/netrepl.janet
@@ -125,11 +125,13 @@
   (default port default-port)
   (eprint "Starting networked repl server on " host ", port " port "...")
   (def name-set @{})
+  (def syspath (dyn :syspath))
   (net/server
     host port
     (fn repl-handler [stream]

       # Setup closures and state
+      (setdyn :syspath syspath)
       (var name "<unknown>")
       (var last-flush 0)
       (def outbuf @"")

Not sure if that's a good way to address things, but the "immediate client disconnect" situation described above was resolved.