fix(smartpdf): clean up SmartNetwork instances during port selection and shutdown
This commit is contained in:
@@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-04-30 - 4.2.2 - fix(smartpdf)
|
||||||
|
clean up SmartNetwork instances during port selection and shutdown
|
||||||
|
|
||||||
|
- stores the temporary SmartNetwork instance used for port discovery so it can be stopped reliably
|
||||||
|
- wraps port availability checks and free-port lookup in a finally block to ensure cleanup on success or failure
|
||||||
|
- extends shutdown logic to stop any remaining SmartNetwork instance alongside the SmartServe server
|
||||||
|
|
||||||
## 2026-04-30 - 4.2.1 - fix(smartpdf)
|
## 2026-04-30 - 4.2.1 - fix(smartpdf)
|
||||||
harden browser lifecycle, port handling, and PDF result metadata
|
harden browser lifecycle, port handling, and PDF result metadata
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartpdf',
|
name: '@push.rocks/smartpdf',
|
||||||
version: '4.2.1',
|
version: '4.2.2',
|
||||||
description: 'A library for creating PDFs dynamically from HTML or websites with additional features like merging PDFs.'
|
description: 'A library for creating PDFs dynamically from HTML or websites with additional features like merging PDFs.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export class SmartPdf {
|
|||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
private smartserveInstance: plugins.smartserve.SmartServe | null = null;
|
private smartserveInstance: plugins.smartserve.SmartServe | null = null;
|
||||||
|
private smartnetworkInstance: plugins.smartnetwork.SmartNetwork | null = null;
|
||||||
serverPort: number = 0;
|
serverPort: number = 0;
|
||||||
headlessBrowser: plugins.smartpuppeteer.puppeteer.Browser | null = null;
|
headlessBrowser: plugins.smartpuppeteer.puppeteer.Browser | null = null;
|
||||||
externalBrowserBool: boolean = false;
|
externalBrowserBool: boolean = false;
|
||||||
@@ -71,7 +72,9 @@ export class SmartPdf {
|
|||||||
|
|
||||||
// Find an available port BEFORE creating server
|
// Find an available port BEFORE creating server
|
||||||
const smartnetworkInstance = new plugins.smartnetwork.SmartNetwork();
|
const smartnetworkInstance = new plugins.smartnetwork.SmartNetwork();
|
||||||
|
this.smartnetworkInstance = smartnetworkInstance;
|
||||||
|
|
||||||
|
try {
|
||||||
if (this._options.port) {
|
if (this._options.port) {
|
||||||
// If a specific port is requested, check if it's available
|
// If a specific port is requested, check if it's available
|
||||||
const isPortAvailable = await smartnetworkInstance.isLocalPortUnused(this._options.port);
|
const isPortAvailable = await smartnetworkInstance.isLocalPortUnused(this._options.port);
|
||||||
@@ -101,6 +104,12 @@ export class SmartPdf {
|
|||||||
}
|
}
|
||||||
this.serverPort = freePort;
|
this.serverPort = freePort;
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
await smartnetworkInstance.stop();
|
||||||
|
if (this.smartnetworkInstance === smartnetworkInstance) {
|
||||||
|
this.smartnetworkInstance = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now setup server using smartserve
|
// Now setup server using smartserve
|
||||||
this.smartserveInstance = new plugins.smartserve.SmartServe({
|
this.smartserveInstance = new plugins.smartserve.SmartServe({
|
||||||
@@ -150,6 +159,11 @@ export class SmartPdf {
|
|||||||
this.smartserveInstance = null;
|
this.smartserveInstance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.smartnetworkInstance) {
|
||||||
|
await this.smartnetworkInstance.stop();
|
||||||
|
this.smartnetworkInstance = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Clear any remaining candidates
|
// Clear any remaining candidates
|
||||||
this._candidates = {};
|
this._candidates = {};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user