forked from LN-Zap/zap-desktop
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(grpc): ensure full disconnect on window close
Do not try to send incoming data from GRPC streams to the main window after the window has been closed. Fix LN-Zap#677
- Loading branch information
Showing
4 changed files
with
40 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import { status } from 'grpc' | ||
import { mainLog } from '../../utils/log' | ||
|
||
export default function subscribeToChannelGraph(mainWindow, lnd, log) { | ||
const call = lnd.subscribeChannelGraph({}) | ||
export default function subscribeToChannelGraph() { | ||
const call = this.lnd.subscribeChannelGraph({}) | ||
|
||
call.on('data', channelGraphData => mainWindow.send('channelGraphData', { channelGraphData })) | ||
call.on('end', () => log.info('end')) | ||
call.on('error', error => error.code !== status.CANCELLED && log.error(error)) | ||
call.on('status', channelGraphStatus => | ||
mainWindow.send('channelGraphStatus', { channelGraphStatus }) | ||
) | ||
call.on('data', channelGraphData => { | ||
if (this.mainWindow) { | ||
this.mainWindow.send('channelGraphData', { channelGraphData }) | ||
} | ||
}) | ||
call.on('end', () => mainLog.info('end')) | ||
call.on('error', error => error.code !== status.CANCELLED && mainLog.error(error)) | ||
call.on('status', channelGraphStatus => { | ||
if (this.mainWindow) { | ||
this.mainWindow.send('channelGraphStatus', { channelGraphStatus }) | ||
} | ||
}) | ||
|
||
return call | ||
} |
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { status } from 'grpc' | ||
import { mainLog } from '../../utils/log' | ||
|
||
export default function subscribeToInvoices(mainWindow, lnd, log) { | ||
const call = lnd.subscribeInvoices({}) | ||
export default function subscribeToInvoices() { | ||
const call = this.lnd.subscribeInvoices({}) | ||
|
||
call.on('data', invoice => { | ||
log.info('INVOICE:', invoice) | ||
mainWindow.send('invoiceUpdate', { invoice }) | ||
mainLog.info('INVOICE:', invoice) | ||
if (this.mainWindow) { | ||
this.mainWindow.send('invoiceUpdate', { invoice }) | ||
} | ||
}) | ||
call.on('end', () => log.info('end')) | ||
call.on('error', error => error.code !== status.CANCELLED && log.error(error)) | ||
call.on('status', status => log.info('INVOICE STATUS:', status)) | ||
call.on('end', () => mainLog.info('end')) | ||
call.on('error', error => error.code !== status.CANCELLED && mainLog.error(error)) | ||
call.on('status', status => mainLog.info('INVOICE STATUS:', status)) | ||
|
||
return call | ||
} |
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { status } from 'grpc' | ||
import { mainLog } from '../../utils/log' | ||
|
||
export default function subscribeToTransactions(mainWindow, lnd, log) { | ||
const call = lnd.subscribeTransactions({}) | ||
export default function subscribeToTransactions() { | ||
const call = this.lnd.subscribeTransactions({}) | ||
|
||
call.on('data', transaction => { | ||
log.info('TRANSACTION:', transaction) | ||
mainWindow.send('newTransaction', { transaction }) | ||
mainLog.info('TRANSACTION:', transaction) | ||
if (this.mainWindow) { | ||
this.mainWindow.send('newTransaction', { transaction }) | ||
} | ||
}) | ||
call.on('end', () => log.info('end')) | ||
call.on('error', error => error.code !== status.CANCELLED && log.error(error)) | ||
call.on('status', status => log.info('TRANSACTION STATUS: ', status)) | ||
call.on('end', () => mainLog.info('end')) | ||
call.on('error', error => error.code !== status.CANCELLED && mainLog.error(error)) | ||
call.on('status', status => mainLog.info('TRANSACTION STATUS: ', status)) | ||
|
||
return call | ||
} |