Skip to content

Commit 2bb5fda

Browse files
committed
fix(memory): use randomBytes for temp filename to avoid concurrent collision
1 parent 3ca92aa commit 2bb5fda

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎src/memory/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SubscribeRequestSchema, UnsubscribeRequestSchema } from "@modelcontextp
66
import { z } from "zod";
77
import { promises as fs } from 'fs';
88
import path from 'path';
9+
import { randomBytes } from 'crypto';
910
import { fileURLToPath } from 'url';
1011

1112
// Define memory file path using environment variable with fallback
@@ -126,7 +127,7 @@ export class KnowledgeGraphManager {
126127
const directory = path.dirname(this.memoryFilePath);
127128
const tempFilePath = path.join(
128129
directory,
129-
`.${path.basename(this.memoryFilePath)}.${process.pid}.${Date.now()}.tmp`
130+
`${path.basename(this.memoryFilePath)}.${randomBytes(16).toString('hex')}.tmp`
130131
);
131132

132133
try {

0 commit comments

Comments
 (0)