-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed an issue where premature client disconnections led to all follo…
…wing requests failing with a 500 error. The underlying file, where the data is saved was closed if any error occurred while reading from the client connection. Subsequently, the file was attempted to be used again, but it is closed.
- Loading branch information
1 parent
2945f6b
commit a006918
Showing
3 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
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
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,38 @@ | ||
import assert from "assert"; | ||
import { Readable } from "stream"; | ||
import FSExtentStore from "../../src/common/persistence/FSExtentStore"; | ||
import IExtentMetadataStore from "../../src/common/persistence/IExtentMetadataStore"; | ||
import { DEFAULT_BLOB_PERSISTENCE_ARRAY } from "../../src/blob/utils/constants"; | ||
import logger from "../../src/common/Logger"; | ||
|
||
import { mock } from "ts-mockito"; | ||
|
||
describe("FSExtentStore", () => { | ||
|
||
const metadataStore: IExtentMetadataStore = mock<IExtentMetadataStore>(); | ||
metadataStore.getExtentLocationId = () => Promise.resolve("Default"); | ||
|
||
it("should handle input stream error gracefully during appendExtent @loki", async () => { | ||
const store = new FSExtentStore(metadataStore, DEFAULT_BLOB_PERSISTENCE_ARRAY, logger); | ||
await store.init(); | ||
|
||
// A null value within the Readable.from array causes the stream to emit an error. | ||
const stream1 = Readable.from(["deadbeef", null], { objectMode: false }); | ||
await assert.rejects(store.appendExtent(stream1)); | ||
|
||
// Write a valid stream to the store. | ||
const stream2 = Readable.from("Test", { objectMode: false }); | ||
const extent = await store.appendExtent(stream2); | ||
assert.strictEqual(extent.offset, 0); | ||
assert.strictEqual(extent.count, 4); | ||
|
||
// Check that the extent is readable. | ||
let readable = await store.readExtent(extent); | ||
const chunks: Buffer[] = []; | ||
for await (const chunk of readable) { | ||
chunks.push(chunk as Buffer); | ||
} | ||
const data = Buffer.concat(chunks); | ||
assert.strictEqual(data.toString(), "Test"); | ||
}); | ||
}); |