-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor svr mgmt & support Handler backends #19
Conversation
I've done basic compile time testing as well as runtime testing of the hook example. Would be good to get some proper tests written. |
0f87c80
to
793c339
Compare
I would recommend reviewing this in Split mode. |
793c339
to
5ee075b
Compare
c9b0217
to
a55be7a
Compare
README.md
Outdated
@@ -71,7 +71,7 @@ The endless server will listen for the following signals: `syscall.SIGHUP`, `sys | |||
|
|||
`syscall.SIGINT` and `syscall.SIGTERM` will trigger a shutdown of the server (it will finish running requests) | |||
|
|||
`SIGUSR2` will trigger [hammerTime](https://github.com/fvbock/endless#hammer-time) | |||
`SIGUSR2` will trigger [Termiante](https://github.com/fvbock/endless#Termination) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mis-spelt Terminate as Termiante here.
👍 (assuming other fixes incoming) |
59e376d
to
9059366
Compare
👍 |
9059366
to
a4d9c3d
Compare
Test coverage is currently 50.9%, big missing element is Restart() which is not simple to test due to the fork. |
Just realised I the kill of the parent isn't just a kill its meant to trigger the shutdown of the parent so it needs to part of the ActionHandler, will need to refactor that too. |
thanks for the pr! |
for testing stuff: there is a rudimentary test that runs manually with restarting... no output is actually tested there but it does the compile send signal stuff and uses ab to hit the server. might be useful. https://github.com/fvbock/endless/blob/master/test/test_restarting.go |
83f5dd8
to
2e7c99f
Compare
I think all issues are addressed now. Changes are quite a bit larger than initial intention as when I added tests more problems came to light. Currently I've made several commits so anyone monitoring the progress can see what's changed, but I'd like to squash them into one before this is merged. |
endless.go
Outdated
// handler to reply to them. Handler is typically nil, in which case the | ||
// DefaultServeMux is used. | ||
// | ||
// In addition to the stl Serve behaviour each connection is added to a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Standard library, clarified
manager.go
Outdated
return l, err | ||
} | ||
|
||
// Register adds a server to the mangers registered servers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
managers, not mangers
6d8a1b5
to
2e4f555
Compare
2e4f555
to
a2d7df7
Compare
@fvbock rebased to fix conflicts |
This moves the built-in signal handling into a pluggable Handler backends which allows endless to support Windows which doesn't support signals. The default Handler on none Windows OS's is a SignalHandler so still maintaining drop in replacement of http.ListenAndServe methods. Server now exports a Restart() method which is the heart of endless. SignalHandler can hook any signal handle however only the following are used internally: * SIGHUP: Call Restart() * SIGUSR2: Call Terminate(0) * SIGINT & SIGTERM: Call Shutdown() Hooked signals now require a function of type SignalHook which takes the triggering os.Signal along with the Server. A Hook can prevent further processing of the signal by returning false. Also: * Renamed HammerTime to TerminateTimeout * Made state management internal using a type for compile time validation. * Removed initialisation of variable to their default values (go vet) * Documented methods. * Cleaned up comment formatting for easier reading. * Added TODO's where potential issues exist. * Made use of http.Server ErrorLog for all logging if not nil otherwise standard logger. * Made TerminateTimeout configurable on each server. * Removed commented out debugging. * Renamed type endlessServer -> Server so its exported and idiomaticly named. * Renamed type and var endlessListener -> Listener so they exported and idomaticly named. * Renamed command line flags to avoid conflict with existing application flags. * Fixed err var shadowing. * Fix syscall.Kill calls on Windows. * Remove isChild from Server as its not needed, use the global instead. * Add state transition validation and error checking. * Exported GetState * Use a done channel to fast bypass a Terminate request. * Corrected comment on keep-alive disable. * Use a safe type cast instead of type switch in Restart.
Add initial tests to validate endless operation. This identified the face the use of panic from excessive wg.Done() calls in Terminate wasn't actually working as the recover only recovers the current goroutine. What was happening was when a handler went to exit normal it would panic and bring the entire server down. Instead we now store each Conn and force close them on terminate; this won't prevent the handlers from continuing to attempt to process but does allow the server to cleanly exit. Also: * Add StateFailed * Remove unneeded wg and lock init in Server{} * Hide output under Debug flag to support tests properly. * Removed disable keep-alives as it only happened for new connections and we close the socket on the next line. * Remove stopped from Listener as it was racey. * Lock conn.Close and use nil listener as the closed flag preventing missing wg.Done if Close returned an unexpected error. * Add listener method which returns the current *Listener * Fixed comment typo's
Previously a server had Restart, Shutdown, Terminate etc methods but these are operations that only make sense globally. In order to fix this we now have a package level Manager which is responsible for these operations. As a side effect of this Handlers now operate on the Manager and not Servers directly. Also: * Allow none tcp listeners * Add restart tests * Fix restarts with multiple servers. Prior to this rework servers whould be shutdown after the first server had started. * Fix windows support by removing reliance on SIGTERM * Switch to ENV based socket ordering, which prevents issues with external cmd flags. * Fix some error checking in tests.
Testing with -race identified data races in connection cleanup, fix these by locking connection cleanup. Avoid process races on Server by using wider locking. Use setState to ensure Server is cleaned up properly when it hits a final state.
fvbock/endless#19 Signed-off-by: Bo-Yi Wu <[email protected]>
Fix bugs with handler
Add integration test, improve handler backend support
I'm afraid it didn't seem to get any traction so it stalled :( |
Closing as its been open since 2015 so doesn't seem like there is a desire to get this merged, which is a shame as I believe it brings in some good changes and enhancements which took a good amount of time to develop. |
Added Manager which is responsible to managing all servers and their actions.
Moves the built-in signal handling into a pluggable Handler backends which allows endless to support Windows which doesn't support signals.
The default Handler on none Windows OS's is a SignalHandler so still maintaining drop in replacement of http.ListenAndServe methods.
Manager now exports a Restart(), Shutdown() and Terminate(..) methods which are the heart of endless.
SignalHandler can hook any signal handle however only the following are used internally:
Hooked signals now require a function of type SignalHook which takes the triggering os.Signal. A Hook can prevent further processing of the signal by returning false.
Also: