Commit a46581e
committed
feat(server): implement graceful shutdown and atomic logging
Implements two key production-readiness features based on code review:
1. **Graceful Shutdown:** The `main.dart` entrypoint now listens for `SIGINT` and `SIGTERM` signals. Upon receiving a signal, it closes the HTTP server to stop accepting new connections, disposes of all application dependencies (like the database connection), and then exits cleanly. This prevents resource leaks.
2. **Atomic Logging:** The logger configuration in `main.dart` has been refactored to use a `StringBuffer` and a single `stdout.write()` call. This ensures that multi-line log entries are written to the console atomically, preventing interleaved output and improving log readability.
A defensive check has also been added to `AppDependencies.dispose` to ensure it can be called safely even if initialization failed.1 parent 758765d commit a46581e
2 files changed
+37
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
42 | 60 | | |
43 | 61 | | |
44 | 62 | | |
| |||
52 | 70 | | |
53 | 71 | | |
54 | 72 | | |
55 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
56 | 77 | | |
57 | 78 | | |
58 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| |||
80 | 83 | | |
81 | 84 | | |
82 | 85 | | |
| 86 | + | |
83 | 87 | | |
84 | 88 | | |
85 | 89 | | |
| |||
268 | 272 | | |
269 | 273 | | |
270 | 274 | | |
271 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
272 | 278 | | |
273 | 279 | | |
274 | 280 | | |
| |||
0 commit comments