Skip to content

Graceful shutdown should not interrupt output printing #140

@LiberalArtist

Description

@LiberalArtist

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions