scosman / zipstreamer

Zip File Streaming Microservice - stream zip files on the fly
MIT License
119 stars 18 forks source link

Exit with ListenAndServe errors #28

Closed danlamanna closed 1 year ago

danlamanna commented 1 year ago

This makes server startup against an already bound port display:

2023/01/25 11:03:28 Server starting on port 4008
2023/01/25 11:03:28 listen tcp :4008: bind: address already in use

Instead of being indistinguishable from a successful start.

scosman commented 1 year ago

Good catch! Silently failing never a good idea!

Not a fan of log.Fatal though. That calls os.Exit and will bypass any cleanup code we add in the future, increasing the chance of introducing bugs down the line.

Mind refactoring to just log.Println the error, and signal the shutdown channel any time that goroutine ends? Should probably cleanup the channel's name and shutdown log string since this this path now runs for cases other than sigterm?

scosman commented 1 year ago

Should probably os.Exit(1) since program is essentially falling here... still torn on skipping any shutdown code though -- that always leads to bugs later. Maybe capture the error and keep single exit path.

danlamanna commented 1 year ago

I'm not sure how to cleanly do this with one channel (not a Go programmer) since I can't put a Signal | string on a single channel, I don't think.

scosman commented 1 year ago

Merging into a branch to make some tweaks before master