Merge pull request #840 from shocknet/crash-debug
throw on exit, not err
This commit is contained in:
commit
3d6a5f8b7d
4 changed files with 41 additions and 14 deletions
|
|
@ -143,6 +143,7 @@ const sendToNostr: NostrSend = (initiator, data, relays) => {
|
|||
}
|
||||
subProcessHandler.Send(initiator, data, relays)
|
||||
}
|
||||
|
||||
send({ type: 'ready' })
|
||||
const supportedKinds = [21000, 21001, 21002, 21003]
|
||||
export default class Handler {
|
||||
|
|
@ -174,8 +175,8 @@ export default class Handler {
|
|||
if (!relay.connected) {
|
||||
throw new Error("failed to connect to relay")
|
||||
}
|
||||
} catch (err) {
|
||||
log("failed to connect to relay, will try again in 2 seconds")
|
||||
} catch (err:any) {
|
||||
log("failed to connect to relay, will try again in 2 seconds", err.message || err)
|
||||
setTimeout(() => {
|
||||
this.Connect()
|
||||
}, 2000)
|
||||
|
|
@ -251,10 +252,16 @@ export default class Handler {
|
|||
}
|
||||
|
||||
async Send(initiator: SendInitiator, data: SendData, relays?: string[]) {
|
||||
try {
|
||||
const keys = this.GetSendKeys(initiator)
|
||||
const privateKey = Buffer.from(keys.privateKey, 'hex')
|
||||
const toSign = await this.handleSend(data, keys)
|
||||
await Promise.all(toSign.map(ue => this.sendEvent(ue, keys, relays)))
|
||||
} catch (e: any) {
|
||||
this.log(ERROR, "failed to send event", e.message || e)
|
||||
throw e
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async handleSend(data: SendData, keys: { name: string, privateKey: string, publicKey: string }): Promise<UnsignedEvent[]> {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { ChildProcess, fork } from 'child_process'
|
|||
import { EnvCanBeInteger, EnvMustBeNonEmptyString } from "../helpers/envParser.js"
|
||||
import { NostrSettings, NostrEvent, ChildProcessRequest, ChildProcessResponse, SendData, SendInitiator } from "./handler.js"
|
||||
import { Utils } from '../helpers/utilsWrapper.js'
|
||||
import {getLogger, ERROR} from '../helpers/logger.js'
|
||||
type EventCallback = (event: NostrEvent) => void
|
||||
|
||||
|
||||
|
|
@ -13,13 +14,22 @@ export default class NostrSubprocess {
|
|||
childProcess: ChildProcess
|
||||
utils: Utils
|
||||
awaitingPongs: (() => void)[] = []
|
||||
log = getLogger({})
|
||||
constructor(settings: NostrSettings, utils: Utils, eventCallback: EventCallback) {
|
||||
this.utils = utils
|
||||
this.childProcess = fork("./build/src/services/nostr/handler")
|
||||
this.childProcess.on("error", (error) => {
|
||||
console.error("nostr subprocess error")
|
||||
throw error
|
||||
this.log(ERROR, "nostr subprocess error", error)
|
||||
})
|
||||
|
||||
this.childProcess.on("exit", (code) => {
|
||||
this.log(ERROR, `nostr subprocess exited with code ${code}`)
|
||||
if (!code) {
|
||||
return
|
||||
}
|
||||
throw new Error(`nostr subprocess exited with code ${code}`)
|
||||
})
|
||||
|
||||
this.childProcess.on("message", (message: ChildProcessResponse) => {
|
||||
switch (message.type) {
|
||||
case 'ready':
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import { PickKeysByType } from 'typeorm/common/PickKeysByType.js';
|
|||
import { deserializeResponseData, serializeRequest, WhereCondition } from './serializationHelpers.js';
|
||||
import { Utils } from '../../helpers/utilsWrapper.js';
|
||||
import { ProcessMetrics } from '../tlv/processMetricsCollector.js';
|
||||
import { getLogger, ERROR } from '../../helpers/logger.js';
|
||||
|
||||
|
||||
export type TX<T> = (txId: string) => Promise<T>
|
||||
|
|
@ -28,7 +29,7 @@ export class StorageInterface extends EventEmitter {
|
|||
private debug: boolean = false;
|
||||
private utils: Utils
|
||||
private dbType: 'main' | 'metrics'
|
||||
|
||||
private log = getLogger({component: 'StorageInterface'})
|
||||
constructor(utils: Utils) {
|
||||
super();
|
||||
this.initializeSubprocess();
|
||||
|
|
@ -56,14 +57,17 @@ export class StorageInterface extends EventEmitter {
|
|||
});
|
||||
|
||||
this.process.on('error', (error: Error) => {
|
||||
console.error('Storage processor error:', error);
|
||||
this.log(ERROR, 'Storage processor error:', error);
|
||||
this.isConnected = false;
|
||||
throw error
|
||||
});
|
||||
|
||||
this.process.on('exit', (code: number) => {
|
||||
console.log(`Storage processor exited with code ${code}`);
|
||||
this.log(ERROR, `Storage processor exited with code ${code}`);
|
||||
this.isConnected = false;
|
||||
if (!code) {
|
||||
return
|
||||
}
|
||||
throw new Error(`Storage processor exited with code ${code}`)
|
||||
});
|
||||
|
||||
this.isConnected = true;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { NostrSend, SendData, SendInitiator } from '../../nostr/handler';
|
|||
import { WebRtcUserInfo } from '../../webRTC';
|
||||
import * as Types from '../../../../proto/autogenerated/ts/types.js'
|
||||
import { ProcessMetrics } from './processMetricsCollector';
|
||||
import { getLogger, ERROR } from '../../helpers/logger.js';
|
||||
export type TlvStorageInterface = {
|
||||
AddTlv: (appId: string, dataName: string, tlv: Uint8Array) => Promise<number>
|
||||
LoadLatest: (limit?: number) => Promise<LatestData>
|
||||
|
|
@ -18,6 +19,7 @@ export class TlvStorageFactory extends EventEmitter {
|
|||
private debug: boolean = false;
|
||||
private _nostrSend: NostrSend = () => { throw new Error('nostr send not initialized yet') }
|
||||
private allowResetMetricsStorages: boolean
|
||||
log = getLogger({component: 'TlvStorageFactory'})
|
||||
constructor(allowResetMetricsStorages: boolean) {
|
||||
super();
|
||||
this.allowResetMetricsStorages = allowResetMetricsStorages
|
||||
|
|
@ -51,13 +53,17 @@ export class TlvStorageFactory extends EventEmitter {
|
|||
});
|
||||
|
||||
this.process.on('error', (error: Error) => {
|
||||
console.error('Tlv Storage processor error:', error);
|
||||
this.log(ERROR, 'Tlv Storage processor error:', error);
|
||||
this.isConnected = false;
|
||||
});
|
||||
|
||||
this.process.on('exit', (code: number) => {
|
||||
console.log(`Tlv Storage processor exited with code ${code}`);
|
||||
this.log(ERROR, `Tlv Storage processor exited with code ${code}`);
|
||||
this.isConnected = false;
|
||||
if (!code) {
|
||||
return
|
||||
}
|
||||
throw new Error(`Tlv Storage processor exited with code ${code}`)
|
||||
});
|
||||
|
||||
this.isConnected = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue