8000 When closing ZAP sometimes a system error shows up by brdandu · Pull Request #1613 · project-chip/zap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

When closing ZAP sometimes a system error shows up #1613

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -17714,7 +17714,7 @@ This mechanism takes care of:
* [JS API: async reporting](#module_JS API_ async reporting)
* [~sendDirtyFlagStatus(db, session)](#module_JS API_ async reporting..sendDirtyFlagStatus)
* [~sendNotificationUpdate(db, session)](#module_JS API_ async reporting..sendNotificationUpdate)
* [~startAsyncReporting(db, intervalMs)](#module_JS API_ async reporting..startAsyncReporting)
* [~startAsyncReporting(db)](#module_JS API_ async reporting..startAsyncReporting)
* [~stopAsyncReporting()](#module_JS API_ async reporting..stopAsyncReporting)

<a name="module_JS API_ async reporting..sendDirtyFlagStatus"></a>
Expand Down Expand Up @@ -17743,15 +17743,14 @@ Sends a dirty flag status for a single session.

<a name="module_JS API_ async reporting..startAsyncReporting"></a>

### JS API: async reporting~startAsyncReporting(db, intervalMs)
### JS API: async reporting~startAsyncReporting(db)
Start the interval that will check and report dirty flags.

**Kind**: inner method of [<code>JS API: async reporting</code>](#module_JS API_ async reporting)

| Param | Type |
| --- | --- |
| db | <code>\*</code> |
| intervalMs | <code>\*</code> |

<a name="module_JS API_ async reporting..stopAsyncReporting"></a>

Expand Down
5 changes: 5 additions & 0 deletions src-electron/db/db-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const fs = require('fs')
const fsp = fs.promises
< 8000 /td> const env = require('../util/env')
const util = require('../util/util.js')
const asyncReporting = require('../util/async-reporting.js')
const dbEnum = require('../../src-shared/db-enum.js')
const dbCache = require('./db-cache')
const dbMapping = require('./db-mapping.js')
Expand Down Expand Up @@ -355,6 +356,8 @@ async function dbMultiInsert(db, sql, arrayOfArrays) {
* @returns A promise that resolves without an argument or rejects with error from the database closing.
*/
async function closeDatabase(database) {
database._closed = true // Mark the database as closed
asyncReporting.stopAsyncReporting()
dbCache.clear()
return new Promise((resolve, reject) => {
env.logSql('About to close database.')
Expand All @@ -372,6 +375,8 @@ async function closeDatabase(database) {
* @param {*} database
*/
function closeDatabaseSync(database) {
database._closed = true // Mark the database as closed
asyncReporting.stopAsyncReporting()
dbCache.clear()
env.logSql('About to close database.')
database.close((err) => {
Expand Down
29 changes: 23 additions & 6 deletions src-electron/util/async-reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ async function sendNotificationUpdate(db, session) {
/**
* Start the interval that will check and report dirty flags.
* @param {*} db
* @param {*} intervalMs
*/
function startAsyncReporting(db) {
for (let key of Object.keys(asyncReports)) {
Expand All @@ -121,14 +120,32 @@ function startAsyncReporting(db) {
// Session based reports get iterated over all sessions
// and called with appropriate session.
report.id = setInterval(async () => {
let sessions = await querySession.getAllSessions(db)
let allPromises = sessions.map((session) => report.fn(db, session))
return Promise.all(allPromises)
try {
// Check if the database is closed. Set in db-api#closeDatabase
if (db._closed) return
let sessions = await querySession.getAllSessions(db)
let allPromises = sessions.map((session) => {
if (db._closed) return
return report.fn(db, session)
})
return Promise.all(allPromises)
} catch (err) {
// If the database was closed during an async operation, we can get an error.
// We can ignore it if the db is marked as closed.
if (db._closed) return
env.logWarning(`Error in session-based async reporting: ${err}`)
}
}, report.intervalMs)
} else {
// Non session based reports get called once with the db as the argument.
report.id = setInterval(() => {
report.fn(db)
report.id = setInterval(async () => {
if (db._closed) return
try {
await report.fn(db)
} catch (err) {
if (db._closed) return // Ignore errors if DB is closed.
env.logWarning(`Error in non-session-based async reporting: ${err}`)
}
}, report.intervalMs)
}
}
Expand Down
0