Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write EPIPE app crash #60

Open
Eonus21 opened this issue Jan 19, 2021 · 7 comments
Open

write EPIPE app crash #60

Eonus21 opened this issue Jan 19, 2021 · 7 comments
Labels

Comments

@Eonus21
Copy link

Eonus21 commented Jan 19, 2021

 events.js:292
       throw er; // Unhandled 'error' event
       ^

 Error: write EPIPE
     at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16)
     at handleWriteReq (internal/stream_base_commons.js:51:26)
     at writeGeneric (internal/stream_base_commons.js:143:15)
     at TLSSocket.Socket._writeGeneric (net.js:786:11)
     at TLSSocket.Socket._write (net.js:798:8)
     at doWrite (_stream_writable.js:403:12)
     at clearBuffer (_stream_writable.js:542:7)
     at onwrite (_stream_writable.js:454:7)
     at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:101:10)
 Emitted 'error' event on TLSSocket instance at:
     at errorOrDestroy (internal/streams/destroy.js:108:12)
     at TLSSocket.onerror (_stream_readable.js:753:7)
     at TLSSocket.emit (events.js:315:20)
     at TLSSocket.EventEmitter.emit (domain.js:482:12)
     at emitErrorNT (internal/streams/destroy.js:92:8)
     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
     at processTicksAndRejections (internal/process/task_queues.js:84:21) {
   errno: 'EPIPE',
   code: 'EPIPE',
   syscall: 'write'
 }

I receive error like this, and it crashes my app. Where I need to make error handler for this?
@Nerixyz

@Eonus21
Copy link
Author

Eonus21 commented Jan 19, 2021

Another such crash log

 events.js:292
       throw er; // Unhandled 'error' event
       ^

 Error: write EPIPE
     at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16)
     at handleWriteReq (internal/stream_base_commons.js:51:26)
     at writeGeneric (internal/stream_base_commons.js:143:15)
     at TLSSocket.Socket._writeGeneric (net.js:786:11)
     at TLSSocket.Socket._write (net.js:798:8)
     at doWrite (_stream_writable.js:403:12)
     at writeOrBuffer (_stream_writable.js:387:5)
     at TLSSocket.Writable.write (_stream_writable.js:318:11)
     at PassThrough.ondata (_stream_readable.js:717:22)
     at PassThrough.emit (events.js:315:20)
     at PassThrough.EventEmitter.emit (domain.js:482:12)
     at addChunk (_stream_readable.js:295:12)
     at readableAddChunk (_stream_readable.js:271:9)
     at PassThrough.Readable.push (_stream_readable.js:212:10)
     at PassThrough.Transform.push (_stream_transform.js:152:32)
     at PassThrough.afterTransform (_stream_transform.js:96:10)
     at PassThrough._transform (_stream_passthrough.js:46:3)
     at PassThrough.Transform._read (_stream_transform.js:191:10)
     at PassThrough.Transform._write (_stream_transform.js:179:12)
     at doWrite (_stream_writable.js:403:12)
     at writeOrBuffer (_stream_writable.js:387:5)
     at PassThrough.Writable.write (_stream_writable.js:318:11)
     at Duplexify._write (/home/inst-ts/node_modules/duplexify/index.js:212:22)
     at doWrite (/home/inst-ts/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:409:139)
     at writeOrBuffer (/home/inst-ts/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:398:5)
     at Duplexify.Writable.write (/home/inst-ts/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:307:11)
     at MQTToTClient.sendData (/home/inst-ts/node_modules/mqtts/dist/mqtt.client.js:234:31)
     at /home/inst-ts/node_modules/mqtts/dist/mqtt.client.js:177:22
 Emitted 'error' event on TLSSocket instance at:
     at errorOrDestroy (internal/streams/destroy.js:108:12)
     at TLSSocket.onerror (_stream_readable.js:753:7)
     at TLSSocket.emit (events.js:315:20)
     at TLSSocket.EventEmitter.emit (domain.js:482:12)
     at emitErrorNT (internal/streams/destroy.js:92:8)
     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
     at processTicksAndRejections (internal/process/task_queues.js:84:21)
     at runNextTicks (internal/process/task_queues.js:66:3)
     at listOnTimeout (internal/timers.js:518:9)
     at processTimers (internal/timers.js:492:7) {
   errno: 'EPIPE',
   code: 'EPIPE',
   syscall: 'write'
 }

@Nerixyz
Copy link
Owner

Nerixyz commented Jan 19, 2021

Do you have any debug logs (withe the DEBUG env-variable; maybe with ig:*,mqtts:*)?

Also, when does this happen? Do you have any code snippet?

@Eonus21
Copy link
Author

Eonus21 commented Jan 20, 2021

Receive this error today again, 3:51 AM. Last app restart was yesterday 4:35 PM.
No, I have not logs now, will enable them today.
I set my .env file as this

DEBUG=ig:*,mqtts:*

Where can I see this logs?
P.S. I use ts-dotenv with my .env file, can it be a problem?

@Eonus21
Copy link
Author

Eonus21 commented Jan 20, 2021

I can show u how I handle fbns & realtime errors

private onRealtimeError = async (err:Error) => {
        if (this.onRealtimeErrorBlock)
            return this.notifier?.notify('Ignoring realtime error (blocked) ' + err.message + ' with ' + this.login) 
        // notify is method to send me logs to telegram (from my bot)
        // I need error block because realtime and fbns emits several errors at the same time
        this.onRealtimeErrorBlock = true

        if ((err.message.indexOf('willReconnect: true') > -1)) {
            this.onRealtimeErrorBlock = false
            return this.notifier?.notify('Ignoring realtime error ' + err.message + ' with ' + this.login)
             // lib will try to reconnect, nothing to do
        }
        if (err.message.indexOf('force destroy') > -1) {
            this.onRealtimeErrorBlock = false
            return this.notifier?.notify('Ignoring realtime error ' + err.message + ' with ' + this.login)
            // someone calls destroy ()
        }
        if ((err.message.indexOf('Expected client to be created') > -1)) {
            this.onRealtimeErrorBlock = false
            return this.notifier?.notify('Ignoring realtime error ' + err.message + ' with ' + this.login)
            // emits after i call this.client.realtime.disconnect
        }
        await this.notifier?.notify('Realtime error:' + err.message + '\nlogin:' + this.login)
        let action = await this.errorHandler.handle(err, ErrorContext.RealtimeError) 
        // error handler makes logs of errors and returns action
        await this.notifier?.notify('Error action ' + action + '\nlogin:' + this.login)
        if (action == ErrorAction.Wait) {
            //try { await this.client.realtime.disconnect() } catch (e) {}
            try { 
                try { await this.promiseWithTimeout<any>(5000, this.client.realtime.disconnect) } catch (e) { this.notifier?.notify('Disconnect error realtime ' + e.message + ' login ' + this.login) } 
                // promise with max duration 5 seconds ( I had problems without this before). 
                // also I try to disconect because I am not sure that on error client was disconnected
                await this.connectRealtime() 
            } catch (e) {
                this.notifier?.notify('Realtime reconnect error \nlogin:' + this.login + '\nerror:' + e.message)
                this.onRealtimeErrorBlock = false
                //this.onRealtimeError(e)
                return
            }
            this.notifier?.notify('Realtime reconnect success \nlogin:' + this.login)
            this.onRealtimeErrorBlock = false
        } else if (action == ErrorAction.Relogin) {
            try { 
                this.restart(false)
            }
            catch (e) {
                this.notifier?.notify('Restart (reason:realtime) error:' + err.message + '\nlogin:' + this.login)
                this.onRealtimeErrorBlock = false
                return
            }
            this.notifier?.notify('Restart success (reason:realtime) \nlogin:' + this.login)
            this.onRealtimeErrorBlock = false
        } else if (action == ErrorAction.Stop) {
            try { 
                await this.forceStop(this.login, this.token)
            }
            catch (e) {
                this.notifier?.notify('Force stop (reason:realtime) error:' + err.message + '\nlogin:' + this.login)
                this.onRealtimeErrorBlock = false
                return
            }
            this.notifier?.notify('Force stop success (reason:realtime) \nlogin:' + this.login)
            this.onRealtimeErrorBlock = false
        } else this.notifier?.notify('Unknown action returned with ' + this.login + ' value:' + action)
    }

connectRealtime () is my function with ig.realtime.connect () inside it.
For fbns I have same as onRealtimeError function, but with fbns instead realtime
Additional - I use proxy, socks5

@Nerixyz
Copy link
Owner

Nerixyz commented Jan 20, 2021

Where can I see this logs?

I think the logs are in stderr.

@Eonus21
Copy link
Author

Eonus21 commented Jan 20, 2021

Okay, I will wait until error ocurs, then check and send to here all information

@Eonus21
Copy link
Author

Eonus21 commented Jan 21, 2021

I receive error like the first time, today 1:43 AM, and no logs. What can I do to enable them?

 events.js:292
       throw er; // Unhandled 'error' event
       ^

 Error: write EPIPE
     at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16)
     at handleWriteReq (internal/stream_base_commons.js:51:26)
     at writeGeneric (internal/stream_base_commons.js:143:15)
     at TLSSocket.Socket._writeGeneric (net.js:786:11)
     at TLSSocket.Socket._write (net.js:798:8)
     at doWrite (_stream_writable.js:403:12)
     at clearBuffer (_stream_writable.js:542:7)
     at onwrite (_stream_writable.js:454:7)
     at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:101:10)
 Emitted 'error' event on TLSSocket instance at:
     at errorOrDestroy (internal/streams/destroy.js:108:12)
     at TLSSocket.onerror (_stream_readable.js:753:7)
     at TLSSocket.emit (events.js:315:20)
     at TLSSocket.EventEmitter.emit (domain.js:482:12)
     at emitErrorNT (internal/streams/destroy.js:92:8)
     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
     at processTicksAndRejections (internal/process/task_queues.js:84:21) {
   errno: 'EPIPE',
   code: 'EPIPE',
   syscall: 'write'
 }

I receive error like this, and it crashes my app. Where I need to make error handler for this?
@Nerixyz

@Nerixyz Nerixyz added the MQTT label Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants