Repository navigation
Commit 03ddb97
fix(memory): implement atomic writes to prevent race condition
Fixes race condition vulnerability where concurrent operations could
corrupt memory.json file by writing incomplete or malformed data.
Changes:
- Add atomic write operations using temporary files and rename
- Import crypto.randomBytes for generating unique temp file names
- Add proper error handling and cleanup for temp files
- Use same pattern as filesystem server for consistency
This resolves JSON parsing errors like 'Unexpected non-whitespace
character after JSON' that occurred when multiple processes
attempted simultaneous file writes.
Fixes #2579
Co-authored-by: Ola Hungerford <[email protected]>1 parent 338d8af commit 03ddb97
1 file changed
Lines changed: 17 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
67 | 83 | | |
68 | 84 | | |
69 | 85 | | |
| |||
0 commit comments