racket / racket/web-server

Graceful shutdown should not interrupt output printing

Open
#140 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Racket
Stars
99
Forks
48
PR merge metrics
No merged PRs in 30d

Description

Consider the following program:

#lang racket
(require web-server/web-server
         racket/async-channel)

(define ach
  (make-async-channel))
(define stop
  (serve #:confirmation-channel ach
         #:port 80 ;<-- needs privileges
         #:dispatch void))
(begin0 (sync ach)
  #;(sleep 1)
  (flush-output (current-error-port))
  (stop)
  (flush-output (current-error-port)))

For me, running in DrRacket (and thus without privileges) typically produces the following output:

🛑 ../../gnu/store/da1fz8sjsy0r21mm02dy7hwqpq08hbzp-racket-pkg-web-server-sources/share/racket/pkgs/web-server-lib/web-server/private/dispatch-server-with-connect-unit.rkt(exn:fail:network:errno
 "tcp-listen: listen failed\n  port number: 80\n  system error: Permission denied; errno=13"
 #<continuation-mark-set>
 '(13 . posix))
>

I've used 🛑 to replace the icons DrRacket prints. The path at the beginning of the message is in printed in red as error output; beginning with the opening parenthesis, the rest is in blue, as a printed value.

Because the program calls (stop) before returning the value of (syn ach), I expected the server to have finished gracefully shutting down, which IMO should include finishing its output to (current-error-port).

In fact, I didn't even need to need to call flush-output, but commenting out the first call (with or without the second call) just changes when the interruption happens. DrRacket still prints its icons, but the path is not printed:

🛑 (exn:fail:network:errno
 "tcp-listen: listen failed\n  port number: 80\n  system error: Permission denied; errno=13"
 #<continuation-mark-set>
 '(13 . posix))

For a Discourse post, I managed to get what I wanted by uncomenting (sleep 1) (with or without the calls to flush-output), but that is obviously a hack.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided Racket program, especially the serve call using #:confirmation-channel and stop. Trace the shutdown path and its output handling; done means stop returns only after the server's error output has finished, without requiring sleep or manual flushing.

Written by the indexing model from the issue text.

Assessment

Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.