harden state durability and disable destructive snapshot sync
This commit is contained in:
@@ -64,13 +64,19 @@ function createHttpServer({ app }) {
|
||||
|
||||
function createMutationPersister({ stateStore, logger = console }) {
|
||||
let queue = Promise.resolve();
|
||||
let lastError = null;
|
||||
|
||||
return {
|
||||
enqueue(state) {
|
||||
queue = queue
|
||||
.then(() => stateStore.save(state))
|
||||
.then(
|
||||
() => stateStore.save(state),
|
||||
() => stateStore.save(state),
|
||||
)
|
||||
.catch((error) => {
|
||||
lastError = error;
|
||||
logger.error({ err: error }, "failed to persist state");
|
||||
throw error;
|
||||
});
|
||||
|
||||
return queue;
|
||||
@@ -78,6 +84,9 @@ function createMutationPersister({ stateStore, logger = console }) {
|
||||
flush() {
|
||||
return queue;
|
||||
},
|
||||
getLastError() {
|
||||
return lastError;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -92,10 +101,15 @@ async function createRuntime({ runtimeConfig = config, logger = console, stateSt
|
||||
try {
|
||||
initialState = await effectiveStateStore.load();
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
{ err: error },
|
||||
"failed to initialize configured state store; falling back to in-memory state",
|
||||
);
|
||||
const allowFallback = runtimeConfig.allowInMemoryStateFallback !== undefined
|
||||
? Boolean(runtimeConfig.allowInMemoryStateFallback)
|
||||
: true;
|
||||
|
||||
if (!allowFallback) {
|
||||
throw new Error("state_store_unavailable_without_fallback", { cause: error });
|
||||
}
|
||||
|
||||
logger.warn({ err: error }, "failed to initialize configured state store; falling back to in-memory state");
|
||||
effectiveStateStore = new InMemoryStateStore();
|
||||
initialState = await effectiveStateStore.load();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user