air-verse / air

☁️ Live reload for Go apps
GNU General Public License v3.0
16.38k stars 772 forks source link

Interpret value of kill_delay as milliseconds #462

Closed lseppala closed 6 months ago

lseppala commented 10 months ago

kill_delay is parsed as a Duration (ref). When given as an integer (as in the example config), it is interpreted as nanoseconds, not milliseconds. The sleep will be too short to allow a program to respond to the interrupt and stop cleanly. This change allows the number to be interpreted as milliseconds.

This change is made to preserve backwards compatibility. If the value is specified as an value under 1 millisecond/1 000 000 nanoseconds, like 500 in the example config, the value will be interpreted as the number of milliseconds. For users who figured out that you may specify the time as a duration string like ”2s” or use large nanosecond integers like 2000000000 for 2 seconds, the behavior will remain the same.

An alternative is changing kill_delay to be parsed as an integer, like delay and rerun_delay. This will break users who used duration strings or large numbers.

This may be the root cause of the problem reported in #216, as a sufficient value for kill_delay to allow a program to stop gracefully solved this problem for me.

satetsu888 commented 9 months ago

related link https://github.com/cosmtrek/air/pull/397

But I think this solution is better, with nice backward compatibility considerations.

xiantang commented 9 months ago

I think the code is great but could u add more test cases for it, once the code is covered i will merge it

lseppala commented 6 months ago

@xiantang Tests cases added. Let me know if you want something different.

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (af962ce) 70.24% compared to head (c28d9a8) 69.31%. Report is 34 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #462 +/- ## ========================================== - Coverage 70.24% 69.31% -0.93% ========================================== Files 9 8 -1 Lines 1035 1046 +11 ========================================== - Hits 727 725 -2 - Misses 235 245 +10 - Partials 73 76 +3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.