Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using os module functions causes root fiber to panic #17

Open
eko234 opened this issue Jan 12, 2022 · 8 comments
Open

Using os module functions causes root fiber to panic #17

eko234 opened this issue Jan 12, 2022 · 8 comments

Comments

@eko234
Copy link

eko234 commented Jan 12, 2022

Hi, I'm trying to write a little web app on circlet and I'm trying to spawn some processes like this one when I receive a request to certain endpoint.

(defn getls
  "gets ls from bin dir" []
  (def procc (os/spawn ["ls"] :p {:in :pipe :out :pipe :err :pipe}))
  (pp :waiting_for_proc)
  (pp (:wait procc))
  [(:read (procc :out) :all)
   (:read (procc :err) :all)])

the first time I get the request nothing happens, but when I try to request again I got an error that says:
current fiber is already waiting for event

could you explain me why this happens? is this a bug or maybe I'm not familiar enough with how things work in Janet or with Circlet

@eko234
Copy link
Author

eko234 commented Jan 12, 2022

this is the code of the application for reference.

(import circlet)

(defn getls
  "gets ls from bin dir" []
  (def procc (os/spawn ["ls"] :p {:in :pipe :out :pipe :err :pipe}))
  (pp :waiting_for_proc)
  (pp (:wait procc))
  [(:read (procc :out) :all)
   (:read (procc :err) :all)])

(defn app
  [req]
  (try
   (do
     (def channel (ev/thread-chan 1))
     (ev/thread (fiber/new (fn [] (ev/give channel (getls)))) :t)
     (def result (ev/take channel))
     {:status 200
      :headers {"Content-Type" "text/html"}
      :body result})
   ([err] 
    (print :WE_GOT_AN_ERROR)
    (print err)
    {:status 500
      :headers {"Content-Type" "text/html"}
      :body :OOPS})))

(defn main "entry point" [& args]
  (circlet/server app 8087))

@eko234
Copy link
Author

eko234 commented Jan 12, 2022

on further debugging, i've found that the problem occurs when I read the streams

@eko234
Copy link
Author

eko234 commented Jan 12, 2022

looks like whenever I try to sync threads, read from other processes something errors out or gets stuck...

@eko234
Copy link
Author

eko234 commented Jan 12, 2022

it must be something with the way circlet handles threads/fibers, doing the same in the joy framework works well, anyhow I would really want to use circlet and understand why this happens.

@harryvederci
Copy link

@eko234 I'm running into similar issues, I think. Have you managed to find a workaround?

@eko234
Copy link
Author

eko234 commented Mar 1, 2022

@eko234 I'm running into similar issues, I think. Have you managed to find a workaround?

Hi fren, you should enter the chat at gitter, backpakin answered me there about it (If I remember correctly), Circlet indeed has some issues with the way it handles threads and thus using fibers or threads directly may lead to these kind of issues, I think in a future this will be fixed (and if I remember well, it has to do with the development of libuv bindings for janet) and I really hope so, but on the other hand there are other libraries you can use for now, I have used both spork for implementing a barebones rpc task manager and the joy framework which says in it description to be "maximalist", but that works pretty well and doesn't even get in my way for it has indeed a very simple and composable api, I use it in production btw.

@ChanderG
Copy link

ChanderG commented Apr 4, 2023

I am facing something similar when I try to use spork's http/request from a circlet handler. Anyway, I have switched to using the the same lib's http/server and that works correctly.

@pepe
Copy link
Member

pepe commented Apr 4, 2023

I would say circlet is not updated for latest Janet. Please do use spork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants