[racket] Closing down the web server

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Fri Oct 12 12:53:22 EDT 2012

Jay, hello.

On 2012 Oct 9, at 20:21, Jay McCarthy wrote:

...and replying in reverse order...

> Regarding if you need to close it... I never close my databases :/ The
> worst that could happen is a TXN gets rolled back when you restart
> because it was happening as you were killing. If you are not worried
> about that... Ctrl-C away!

Ahh, of course.  Transactions good; me like transactions.  I have duly stopped worrying about the problem.  Happy me.

>> That's my situation, too.  The server is started from a shell, but it opens a database connection (in fact using (planet "sqlite.rkt" ("jaymccarthy" "sqlite.plt" 5 1)), for which many thanks!), and I feel sure I should be carefully calling (close db) at some point.  I haven't been doing so, so far, and nothing's broken, but I don't write to the database very often so I guess I've just got away with it up to now.
> You should switch to using the built-in 'db' library if possible. Ryan
> has fixed some errors and is otherwise doing a better job maintaining.

I've done so -- thanks for the suggestion -- and it's all working smoothly.

> You could do...
> (define we (make-will-executor)
> (will-register we db sql:close)
> (define we-t (thread (lambda () (will-execute we))))
> And when the db was unreachable (because its custodian/thread/etc was
> killed), then the db would be closed. I believe you would have to
> ensure that we-t is not within the control of the same custodian.

Most useful as a pattern -- thanks again.  Since the relevant 'prove unreachable' happens in the GC, presumably there's no guarantee that the will associated with db will be executed, when the server (in this case) is shut down.  No longer a problem in this case, so I ask purely for the sake of completeness.

Best wishes,


Norman Gray  :  http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK

Posted on the users mailing list.