Search code examples
multithreadinglisphunchentoot

hunchentoot-based app in a lisp image (from buildapp) immediately returns


So I have an application using restas, based on hunchentoot.

At some point, I have the following function:

(defun main (args)
  (declare (ignore args))
  (set-config)
  (restas:start '#:spa :port 8080))

(set-config) sets a few values related to database.

Anyway, I then use buildapp in the following way:

buildapp --output dist/spa --load-system spa --asdf-tree ~/quicklisp/ --entry spa::main --compress-core

Which works perfectly. The (set-config) function requires a config.json file to be present, and it indeed doesn't work when the file doesn't exist, so I know for sure that the application is correctly compiled.

When I run the generated binary however, the application immediately returns. Which means the HTTP server doesn't stay up.

I guess it's related to the fact that hunchentoot spawns a new thread, but it shouldn't stop the process, should it?

Also, I don't want to not use threads, i.e. I want the fact that each request is a separate thread.

So... I'm not sure exactly why it immediately returns. Why? And how to fix it?


Solution

  • I guess that you have to enter a main loop to keep the program running. The example at http://www.xach.com/lisp/buildapp/ uses the SBCL-specific (sb-impl::toplevel-repl nil).