Skip to content

Commit

Permalink
update console-event-handler to elide specific <child-end> messages
Browse files Browse the repository at this point in the history
<child-end> messages where the exit reason is normal or shutdown and
have no stack details are expected and are generally not useful. The
exiting process may be killed by their supervisor so the killed field
is ignored.
  • Loading branch information
payneca authored and owaddell-beckman committed Feb 23, 2024
1 parent fc1fca3 commit e7edb98
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/swish/app-core.ss
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
[(int32? exit-code) exit-code]
[(eq? exit-code (void)) 0]
[else
(console-event-handler (format "application shutdown due to (exit ~s)" exit-code))
($console-event-handler (format "application shutdown due to (exit ~s)" exit-code))
1]))

(profile-omit ;; profiler won't have a chance to save data for these due to osi_exit
Expand Down
56 changes: 16 additions & 40 deletions src/swish/app.ms
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,9 @@
(app:shutdown 1)
(receive (after 100 (osi_exit 3))))))
'("expected non-zero exit")))
[#(EXIT `(<os-process-failed> [exit-status 1] ,stdout ,stderr))
(match-regexps '("ok") stdout)
(match-regexps
'(seek #0="Event: #\\(<child-end> .*\\)" seek #0# seek #0# "") stderr)]
[#(EXIT `(<os-process-failed> [exit-status 1] ,stdout [stderr ()]))
(match (match-regexps '("ok") stdout)
[() 'no-extraneous-output])]
[#(EXIT `(<os-process-failed> [exit-status 3] ,stderr))
(printf "~{~a\n~}" stderr)
(throw 'matched-wrong-case)]))
Expand All @@ -461,16 +460,10 @@
(cdr 7))))))
(match (catch (script-test script '() "" '("expected non-zero exit")))
[#(EXIT `(<os-process-failed> ,stdout ,stderr))
(match-regexps '() stdout)
(match-regexps
'("^script: 7 is not a pair[.]$"
""
"^Date: "
"^Timestamp: "
#0="Event: #\\(<child-end> .*\\)"
seek #0#
seek #0# "")
stderr)]))
(match (match-regexps '() stdout)
[() 'no-extraneous-output])
(match (match-regexps '("^script: 7 is not a pair[.]$") stderr)
[() 'no-extraneous-output])]))

(isolate-mat application-shutdown4 ()
;; Test for regression where application doesn't shut down when we
Expand All @@ -486,16 +479,10 @@
(spawn&link (lambda () (raise 'issue)))))
'("expected non-zero exit")))
[#(EXIT `(<os-process-failed> [exit-status 2] ,stdout ,stderr))
(match-regexps '("ok") stdout)
(match-regexps
'("^Exception: issue[.]$"
""
"^Date: "
"^Timestamp: "
#0="Event: #\\(<child-end> .*\\)"
seek #0#
seek #0# "")
stderr)]))
(match (match-regexps '("ok") stdout)
[() 'no-extraneous-output])
(match (match-regexps '("^Exception: issue[.]$") stderr)
[() 'no-extraneous-output])]))

(meta-cond
[(memq (machine-type) '(i3nt ti3nt a6nt ta6nt))
Expand Down Expand Up @@ -545,22 +532,11 @@
(receive (after 1500 'fail)
[#(process-terminated ,@os-pid ,@expected-exit-code ,@expected-signal)
'ok])])
(match-regexps
'(seek
"Date: "
"Timestamp: "
"Event: #\\(<child-end>.*normal #f\\)"
seek
"Date: "
"Timestamp: "
"Event: #\\(<child-end>.*shutdown #f\\)"
seek
"Date: "
"Timestamp: "
"Event: #\\(<child-end>.*shutdown #f\\)")
(let f ()
(receive (after 0 '())
[(,@from-stderr . ,msg) (cons msg (f))])))
(match (match-regexps '()
(let f ()
(receive (after 0 '())
[(,@from-stderr . ,msg) (cons msg (f))])))
[() 'no-extraneous-output])
'ok)))
(test SIGINT)
(test SIGTERM))])
Expand Down
2 changes: 1 addition & 1 deletion src/swish/application.ss
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
(match (gen-server:start 'application starter)
[#(ok ,_) 'ok]
[#(error ,reason)
(console-event-handler `#(application-start-failed ,reason))
($console-event-handler `#(application-start-failed ,reason))
(exit 1)]))

)
6 changes: 3 additions & 3 deletions src/swish/erlang.ss
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
#!chezscheme
(library (swish erlang)
(export
$console-event-handler
DOWN
EXIT
add-finalizer
arg-check
bad-arg
catch
complete-io
console-event-handler
dbg
define-match-extension
define-tuple
Expand Down Expand Up @@ -246,7 +246,7 @@

(define (panic event)
(on-exit (osi_exit 80)
(console-event-handler event)))
($console-event-handler event)))

(define (@kill p raw-reason)
(define reason (unwrap-fault-condition raw-reason))
Expand Down Expand Up @@ -1041,7 +1041,7 @@
(define event-loop-process #f)
(define finalizer-process #f)

(define (console-event-handler event)
(define ($console-event-handler event)
(with-interrupts-disabled
(parameterize ([print-graph #t])
(let ([op (console-error-port)]
Expand Down
18 changes: 17 additions & 1 deletion src/swish/event-mgr-notify.ss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#!chezscheme
(library (swish event-mgr-notify)
(export
console-event-handler
event-mgr:notify
informative-exit-reason?
normalize-exit-reason
Expand All @@ -31,14 +32,18 @@
(import
(chezscheme)
(swish erlang)
(swish events)
(swish internal)
(swish meta)
)

($import-internal make-fault-condition &fault-condition)

(define (normal? reason)
(and (memq reason '(normal shutdown)) #t))

(define (abnormal? reason)
(not (memq reason '(normal shutdown))))
(not (normal? reason)))

(define normalize-exit-reason
(case-lambda
Expand Down Expand Up @@ -72,6 +77,17 @@
[else (console-event-handler event)])
'ok)

(define (console-event-handler event)
;; During a normal application shutdown, after event-mgr is
;; unregistered, the exiting processes may still be marked
;; killed. Ignore normal reasons as long as there are no
;; associated stack details.
(match event
[`(<child-end> ,reason [details #f])
(guard (normal? reason))
(void)]
[,_ ($console-event-handler event)]))

(define-syntax (system-detail x)
(syntax-case x ()
[(_ name [field value] ...)
Expand Down
69 changes: 29 additions & 40 deletions src/swish/swish-build.ms
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,14 @@
(run-fat "hook-exit" '() expected-output))

(isolate-mat application-shutdown ()
(define event "Event: #\\(<child-end> [0-9]+ #<process [0-9]+:[0-9]+> 1 (normal|shutdown)")
(define expected-output
`(seek "Date:" "Timestamp:" ,event
seek "Date:" "Timestamp:" ,event
seek "Date:" "Timestamp:" ,event))
(define (exit-status err)
(match err
[`(catch `(<os-process-failed> [stdout ()] [stderr ()] ,exit-status))
exit-status]
[,_
;; Expect no stdout or stderr. If we get here, we've violated
;; that assumption.
(raise err)]))
(define app-shutdown
(write-test-file "app-shutdown.ss"
(lambda ()
Expand All @@ -767,41 +770,27 @@
(app:shutdown 42)
(receive))]))))))
(set-file-mode app-shutdown #o755)
;; run as /usr/bin/env script
(run-bash "app-shutdown.ss" '("normal") expected-output)
(match (catch (run-bash "app-shutdown.ss" '("abnormal") '()))
[#(EXIT `(<os-process-failed> ,stderr [exit-status 2]))
(match-regexps expected-output stderr)])
(match (catch (run-bash "app-shutdown.ss" '("specific") '()))
[#(EXIT `(<os-process-failed> ,stderr [exit-status 42]))
(match-regexps expected-output stderr)])
;; run as swish script
(run-script app-shutdown '("normal") expected-output)
(match (catch (run-script app-shutdown '("abnormal") expected-output))
[#(EXIT `(<os-process-failed> ,stderr [exit-status 2]))
(match-regexps expected-output stderr)])
(match (catch (run-script app-shutdown '("specific") expected-output))
[#(EXIT `(<os-process-failed> ,stderr [exit-status 42]))
(match-regexps expected-output stderr)])
;; run as thin app
(build-example "app-shutdown" '())
(run-thin "app-shutdown" '("normal") expected-output)
(match (catch (run-thin "app-shutdown" '("abnormal") '()))
[#(EXIT `(<os-process-failed> ,stderr [exit-status 2]))
(match-regexps expected-output stderr)])
(match (catch (run-thin "app-shutdown" '("specific") '()))
[#(EXIT `(<os-process-failed> ,stderr [exit-status 42]))
(match-regexps expected-output stderr)])
(assert (delete-file (output-file "app-shutdown")))
;; run as fat app
(build-example "app-shutdown" '("--rtlib" "swish" "-b" "petite"))
(run-fat "app-shutdown" '("normal") expected-output)
(match (catch (run-fat "app-shutdown" '("abnormal") '()))
[#(EXIT `(<os-process-failed> ,stderr [exit-status 2]))
(match-regexps expected-output stderr)])
(match (catch (run-fat "app-shutdown" '("specific") '()))
[#(EXIT `(<os-process-failed> ,stderr [exit-status 42]))
(match-regexps expected-output stderr)]))
(match-let*
(;; run as /usr/bin/env script
[() (run-bash "app-shutdown.ss" '("normal") '())]
[2 (exit-status (try (run-bash "app-shutdown.ss" '("abnormal") '())))]
[42 (exit-status (try (run-bash "app-shutdown.ss" '("specific") '())))]
;; run as swish script
[() (run-script app-shutdown '("normal") '())]
[2 (exit-status (try (run-script app-shutdown '("abnormal") '())))]
[42 (exit-status (try (run-script app-shutdown '("specific") '())))]
;; run as thin app
[() (build-example "app-shutdown" '())]
[() (run-thin "app-shutdown" '("normal") '())]
[2 (exit-status (try (run-thin "app-shutdown" '("abnormal") '())))]
[42 (exit-status (try (run-thin "app-shutdown" '("specific") '())))]
[,_ (assert (delete-file (output-file "app-shutdown")))]
;; run as fat app
[() (build-example "app-shutdown" '("--rtlib" "swish" "-b" "petite"))]
[() (run-fat "app-shutdown" '("normal") '())]
[2 (exit-status (try (run-fat "app-shutdown" '("abnormal") '())))]
[42 (exit-status (try (run-fat "app-shutdown" '("specific") '())))])
'ok))

(isolate-mat compile-library ()
(define source (input-file "clib"))
Expand Down

0 comments on commit e7edb98

Please sign in to comment.