Commit 9158d62
committed
[fit] feat(resources): implement three-level cleanup for HTTP request lifecycle
This commit introduces a robust resource release mechanism across three critical layers to prevent memory leaks and state pollution in long-lived connections:
1. **Pre-request cleanup**
Added `clearRequest(ctx)` at the beginning of `channelRead()` in the first business handler to reset Channel-scoped attributes (e.g., `AttributeKey<RequestContext>`) before processing new requests[1,2](@ref). This ensures isolated request states without cross-request contamination.
2. **Exception-triggered cleanup**
Enhanced `exceptionCaught()` to immediately release:
Followed by `ctx.close()` to guarantee `channelInactive()` invocation.
3. **Connection termination safeguard**
Strengthened `channelInactive()` to perform defensive cleanup of:
This triple-layer approach covers:
✅ Normal request processing paths
✅ Connection closures (client/timeout/graceful shutdown)
✅ All exception scenarios (I/O errors, decoding failures, business logic crashes)
Fixes #145 (Resource leak during connection reset)1 parent efd61f0 commit 9158d62
File tree
3 files changed
+18
-16
lines changed- framework/fit/java/fit-builtin
- plugins/fit-http-server-netty/src
- main/java/modelengine/fit/http/server/netty
- test/java/modelengine/fit/http/server/netty
- services/fit-http-classic/definition/src/main/java/modelengine/fit/http/server/support
3 files changed
+18
-16
lines changedLines changed: 15 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | | - | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | | - | |
| 97 | + | |
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
100 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
101 | 110 | | |
102 | 111 | | |
103 | 112 | | |
| |||
117 | 126 | | |
118 | 127 | | |
119 | 128 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | 129 | | |
127 | 130 | | |
128 | 131 | | |
| |||
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
| 141 | + | |
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| |||
184 | 188 | | |
185 | 189 | | |
186 | 190 | | |
187 | | - | |
| 191 | + | |
188 | 192 | | |
189 | 193 | | |
190 | | - | |
191 | | - | |
| 194 | + | |
192 | 195 | | |
193 | 196 | | |
194 | 197 | | |
195 | | - | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | | - | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
121 | 120 | | |
122 | 121 | | |
123 | 122 | | |
| |||
0 commit comments