Commit 6f5c34e
fix: Close underlying Writers in RecordingSession to prevent resource leaks
The fastjson JSONWriter.close() method does not close the underlying
Writer passed to its constructor - it only closes the internal
SerializeWriter, which has no effect. This caused FileOutputStream and
OutputStreamWriter instances to leak in RecordingSession.
Changes:
- Make AppMapSerializer implement AutoCloseable and track the underlying
Writer to close it explicitly
- Add try-with-resources for AppMapSerializer in checkpoint() to ensure
proper cleanup on exceptions
- Add try-finally in stop() to ensure serializer is closed even if
write() fails
- Consolidate JSON finalization and closing logic into close() method,
removing the redundant finish() method
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 64fcc6b commit 6f5c34e
File tree
2 files changed
+50
-25
lines changed- agent/src/main/java/com/appland/appmap/record
2 files changed
+50
-25
lines changedLines changed: 20 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
| 46 | + | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| |||
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
76 | | - | |
| 79 | + | |
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
| |||
280 | 283 | | |
281 | 284 | | |
282 | 285 | | |
283 | | - | |
| 286 | + | |
284 | 287 | | |
285 | 288 | | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
290 | 303 | | |
291 | 304 | | |
Lines changed: 30 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
101 | 107 | | |
102 | | - | |
103 | | - | |
| 108 | + | |
104 | 109 | | |
105 | | - | |
106 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
107 | 113 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | 114 | | |
113 | 115 | | |
114 | 116 | | |
| |||
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
| 129 | + | |
127 | 130 | | |
128 | 131 | | |
129 | 132 | | |
130 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
131 | 145 | | |
132 | 146 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | 147 | | |
138 | 148 | | |
139 | 149 | | |
| |||
163 | 173 | | |
164 | 174 | | |
165 | 175 | | |
166 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
167 | 179 | | |
168 | 180 | | |
169 | 181 | | |
| |||
0 commit comments