-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(KeyValueStore): big buffers should not crash (#1734)
Closes #1732 Closes #1710 Simple fix really, tell shapeshift inputs can be buffers too (I'll also see if we can add a generic "just check that its an object" in shapeshift for times like these)
- Loading branch information
1 parent
432904a
commit 2f682f7
Showing
4 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/memory-storage/test/no-crash-on-big-buffers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// https://github.com/apify/crawlee/issues/1732 | ||
// https://github.com/apify/crawlee/issues/1710 | ||
|
||
import { rm } from 'node:fs/promises'; | ||
import { resolve } from 'node:path'; | ||
import { MemoryStorage } from '@crawlee/memory-storage'; | ||
import type { KeyValueStoreClient, KeyValueStoreInfo } from '@crawlee/types'; | ||
|
||
describe('MemoryStorage should not crash when saving a big buffer', () => { | ||
const tmpLocation = resolve(__dirname, './tmp/no-buffer-crash'); | ||
const storage = new MemoryStorage({ | ||
localDataDirectory: tmpLocation, | ||
persistStorage: false, | ||
}); | ||
|
||
let kvs: KeyValueStoreInfo; | ||
let store: KeyValueStoreClient; | ||
|
||
beforeAll(async () => { | ||
kvs = await storage.keyValueStores().getOrCreate(); | ||
store = storage.keyValueStore(kvs.id); | ||
}); | ||
|
||
afterAll(async () => { | ||
await rm(tmpLocation, { force: true, recursive: true }); | ||
}); | ||
|
||
test('should not crash when saving a big buffer', async () => { | ||
let zip: Buffer; | ||
|
||
if (process.env.CRAWLEE_DIFFICULT_TESTS) { | ||
const numbers = Array.from(([...Array(18_100_000).keys()]).map((i) => i * 3_000_000)); | ||
|
||
zip = Buffer.from([...numbers]); | ||
} else { | ||
zip = Buffer.from([...Array(100_000)].map((i) => i * 8)); | ||
} | ||
|
||
try { | ||
await store.setRecord({ key: 'owo.zip', value: zip }); | ||
} catch (err) { | ||
expect(err).not.toBeDefined(); | ||
} | ||
}); | ||
}); |