Implement WASM instance restart to handle out of memory error (#81)

* Test case for wasm out of memory error

* Restart wasm instance after N blocks

* Handle out of memory error and re instantiate WASM

* Remove old instance from map before reinstantiating WASM
This commit is contained in:
2021-12-28 16:08:05 +05:30
committed by nabarun
parent 68bc1c00db
commit 198e49e5a0
29 changed files with 181 additions and 63 deletions
@@ -49,7 +49,7 @@ const main = async (): Promise<void> => {
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
@@ -46,7 +46,7 @@ const main = async (): Promise<void> => {
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
@@ -50,7 +50,7 @@ export const main = async (): Promise<any> => {
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
@@ -46,7 +46,7 @@ const main = async (): Promise<void> => {
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
@@ -44,7 +44,7 @@ export const handler = async (argv: any): Promise<void> => {
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
@@ -62,7 +62,7 @@ const main = async (): Promise<void> => {
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
+1 -1
View File
@@ -61,7 +61,7 @@ export const main = async (): Promise<any> => {
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
@@ -21,8 +21,7 @@ import {
QUEUE_IPFS,
JobQueueConfig,
DEFAULT_CONFIG_PATH,
initClients,
JOB_KIND_INDEX
initClients
} from '@vulcanize/util';
import { GraphWatcher, Database as GraphDatabase } from '@vulcanize/graph-node';
@@ -57,12 +56,6 @@ export class JobRunner {
// TODO Call pre-block hook here (Directly or indirectly (Like done through indexer.processEvent for events)).
await this._baseJobRunner.processBlock(job);
const { data: { kind, blockHash, blockNumber } } = job;
if (kind === JOB_KIND_INDEX) {
await this._indexer.processBlock(blockHash, blockNumber);
}
});
}
@@ -138,7 +131,7 @@ export const main = async (): Promise<any> => {
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
+1 -1
View File
@@ -46,7 +46,7 @@ export const main = async (): Promise<any> => {
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries