@mastra/deployer 1.61.0-alpha.2 → 1.61.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/server/handlers/client.d.ts +7 -0
- package/dist/server/handlers/client.d.ts.map +1 -1
- package/dist/server/index.cjs +58 -20
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +58 -20
- package/dist/server/index.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @mastra/deployer
|
|
2
2
|
|
|
3
|
+
## 1.61.0-alpha.3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Improved generated server shutdown to drain in-flight HTTP requests before closing Mastra resources ([#20678](https://github.com/mastra-ai/mastra/issues/20678)). Refresh streams now close during shutdown, drain failures no longer skip resource cleanup, and a second shutdown signal exits immediately. ([#21990](https://github.com/mastra-ai/mastra/pull/21990))
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`9267e9b`](https://github.com/mastra-ai/mastra/commit/9267e9b3d9c2fcf16936050495a787054c2431ab), [`acc3471`](https://github.com/mastra-ai/mastra/commit/acc3471de5f3fde8027ee4e355af292b2bc1bc30), [`b6a771e`](https://github.com/mastra-ai/mastra/commit/b6a771ef23d203ddb348efca8065eff65def8191), [`9267e9b`](https://github.com/mastra-ai/mastra/commit/9267e9b3d9c2fcf16936050495a787054c2431ab), [`26d4016`](https://github.com/mastra-ai/mastra/commit/26d40160ff7f7d8bf95fee2039a52cbc83863533), [`9267e9b`](https://github.com/mastra-ai/mastra/commit/9267e9b3d9c2fcf16936050495a787054c2431ab), [`9267e9b`](https://github.com/mastra-ai/mastra/commit/9267e9b3d9c2fcf16936050495a787054c2431ab), [`57c5103`](https://github.com/mastra-ai/mastra/commit/57c51035a2a36e3df3c4f32f46bb789a66ed5946)]:
|
|
12
|
+
- @mastra/server@1.61.0-alpha.3
|
|
13
|
+
- @mastra/core@1.61.0-alpha.3
|
|
14
|
+
|
|
3
15
|
## 1.61.0-alpha.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-deployer
|
|
|
3
3
|
description: Documentation for @mastra/deployer. Use when working with @mastra/deployer APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/deployer"
|
|
6
|
-
version: "1.61.0-alpha.
|
|
6
|
+
version: "1.61.0-alpha.3"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { Context } from 'hono';
|
|
2
2
|
export declare function handleClientsRefresh(c: Context): Response;
|
|
3
|
+
/**
|
|
4
|
+
* End every open refresh SSE stream. Studio keeps one of these connections
|
|
5
|
+
* open for its whole lifetime, so without this the graceful-shutdown drain
|
|
6
|
+
* would wait on them until the drain deadline (stalling `mastra dev` hot
|
|
7
|
+
* reloads while Studio is open).
|
|
8
|
+
*/
|
|
9
|
+
export declare function closeRefreshStreams(): void;
|
|
3
10
|
export declare function handleTriggerClientsRefresh(c: Context): Response & import("hono").TypedResponse<{
|
|
4
11
|
success: true;
|
|
5
12
|
clients: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAKpC,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,GAAG,QAAQ,CAoBzD;AAED,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,OAAO;;;kEASrD;AAGD,wBAAgB,gBAAgB,SAG/B;AAED,wBAAgB,eAAe,SAG9B;AAED,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C"}
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAKpC,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,GAAG,QAAQ,CAoBzD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,SASlC;AAED,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,OAAO;;;kEASrD;AAGD,wBAAgB,gBAAgB,SAG/B;AAED,wBAAgB,eAAe,SAG9B;AAED,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C"}
|
package/dist/server/index.cjs
CHANGED
|
@@ -3768,6 +3768,20 @@ function handleClientsRefresh(c) {
|
|
|
3768
3768
|
"Access-Control-Allow-Origin": "*"
|
|
3769
3769
|
} });
|
|
3770
3770
|
}
|
|
3771
|
+
/**
|
|
3772
|
+
* End every open refresh SSE stream. Studio keeps one of these connections
|
|
3773
|
+
* open for its whole lifetime, so without this the graceful-shutdown drain
|
|
3774
|
+
* would wait on them until the drain deadline (stalling `mastra dev` hot
|
|
3775
|
+
* reloads while Studio is open).
|
|
3776
|
+
*/
|
|
3777
|
+
function closeRefreshStreams() {
|
|
3778
|
+
clients.forEach((controller) => {
|
|
3779
|
+
try {
|
|
3780
|
+
controller.close();
|
|
3781
|
+
} catch {}
|
|
3782
|
+
});
|
|
3783
|
+
clients.clear();
|
|
3784
|
+
}
|
|
3771
3785
|
function handleTriggerClientsRefresh(c) {
|
|
3772
3786
|
clients.forEach((controller) => {
|
|
3773
3787
|
try {
|
|
@@ -4633,6 +4647,8 @@ async function createNodeServer(mastra, options = { tools: {} }) {
|
|
|
4633
4647
|
const injectWebSocket = app.injectWebSocket;
|
|
4634
4648
|
const serverOptions = mastra.getServer();
|
|
4635
4649
|
const apiPrefix = serverOptions?.apiPrefix ?? "/api";
|
|
4650
|
+
const drainTimeoutMs = serverOptions?.drainTimeout ?? 5e3;
|
|
4651
|
+
if (serverOptions?.handleShutdownSignals !== false && (!Number.isFinite(drainTimeoutMs) || drainTimeoutMs < 0 || drainTimeoutMs > 2147483647)) throw new RangeError("server.drainTimeout must be a finite number between 0 and 2147483647 milliseconds");
|
|
4636
4652
|
const key = serverOptions?.https?.key ?? (process.env.MASTRA_HTTPS_KEY ? Buffer.from(process.env.MASTRA_HTTPS_KEY, "base64") : void 0);
|
|
4637
4653
|
const cert = serverOptions?.https?.cert ?? (process.env.MASTRA_HTTPS_CERT ? Buffer.from(process.env.MASTRA_HTTPS_CERT, "base64") : void 0);
|
|
4638
4654
|
const isHttpsEnabled = Boolean(key && cert);
|
|
@@ -4674,33 +4690,55 @@ async function createNodeServer(mastra, options = { tools: {} }) {
|
|
|
4674
4690
|
else await workerLifecycle.startEventEngine();
|
|
4675
4691
|
import("@mastra/core/telemetry").then(({ syncUsageTelemetry }) => syncUsageTelemetry(mastra)).catch(() => {});
|
|
4676
4692
|
import("@mastra/core/telemetry").then(({ syncFeatureUsageTelemetry }) => syncFeatureUsageTelemetry(mastra)).catch(() => {});
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
shuttingDown = true;
|
|
4682
|
-
const logger = mastra.getLogger();
|
|
4683
|
-
logger.info("Shutting down Mastra server", { signal });
|
|
4684
|
-
server.close();
|
|
4685
|
-
const lifecycle = mastra;
|
|
4686
|
-
if (typeof lifecycle.shutdown === "function") {
|
|
4693
|
+
if (serverOptions?.handleShutdownSignals !== false) {
|
|
4694
|
+
const CORE_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
4695
|
+
const timedOut = Symbol("shutdown-timeout");
|
|
4696
|
+
const race = async (work, ms) => {
|
|
4687
4697
|
let timeout;
|
|
4688
|
-
const timedOut = Symbol("shutdown-timeout");
|
|
4689
4698
|
const timeoutPromise = new Promise((resolve) => {
|
|
4690
|
-
timeout = setTimeout(() => resolve(timedOut),
|
|
4699
|
+
timeout = setTimeout(() => resolve(timedOut), ms);
|
|
4691
4700
|
});
|
|
4692
4701
|
try {
|
|
4693
|
-
|
|
4694
|
-
} catch (error) {
|
|
4695
|
-
logger.error("Error during Mastra shutdown", { error });
|
|
4702
|
+
return await Promise.race([work, timeoutPromise]);
|
|
4696
4703
|
} finally {
|
|
4697
4704
|
clearTimeout(timeout);
|
|
4698
4705
|
}
|
|
4699
|
-
}
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4706
|
+
};
|
|
4707
|
+
let shuttingDown = false;
|
|
4708
|
+
const shutdown = async (signal) => {
|
|
4709
|
+
if (shuttingDown) {
|
|
4710
|
+
process.exit(1);
|
|
4711
|
+
return;
|
|
4712
|
+
}
|
|
4713
|
+
shuttingDown = true;
|
|
4714
|
+
const logger = mastra.getLogger();
|
|
4715
|
+
logger.info("Shutting down Mastra server", { signal });
|
|
4716
|
+
try {
|
|
4717
|
+
const drained = new Promise((resolve) => {
|
|
4718
|
+
server.close(() => resolve());
|
|
4719
|
+
});
|
|
4720
|
+
closeRefreshStreams();
|
|
4721
|
+
server.closeIdleConnections?.();
|
|
4722
|
+
if (await race(drained, drainTimeoutMs) === timedOut) {
|
|
4723
|
+
logger.warn("Mastra server drain timed out; closing remaining HTTP connections", { timeoutMs: drainTimeoutMs });
|
|
4724
|
+
server.closeAllConnections?.();
|
|
4725
|
+
}
|
|
4726
|
+
} catch (error) {
|
|
4727
|
+
logger.error("Error while draining Mastra server", { error });
|
|
4728
|
+
}
|
|
4729
|
+
try {
|
|
4730
|
+
const lifecycle = mastra;
|
|
4731
|
+
if (typeof lifecycle.shutdown === "function") {
|
|
4732
|
+
if (await race(lifecycle.shutdown(), CORE_SHUTDOWN_TIMEOUT_MS) === timedOut) logger.warn("Mastra shutdown timed out; forcing exit", { timeoutMs: CORE_SHUTDOWN_TIMEOUT_MS });
|
|
4733
|
+
}
|
|
4734
|
+
} catch (error) {
|
|
4735
|
+
logger.error("Error during Mastra shutdown", { error });
|
|
4736
|
+
}
|
|
4737
|
+
process.exit(0);
|
|
4738
|
+
};
|
|
4739
|
+
process.on("SIGINT", () => void shutdown("SIGINT"));
|
|
4740
|
+
process.on("SIGTERM", () => void shutdown("SIGTERM"));
|
|
4741
|
+
}
|
|
4704
4742
|
return server;
|
|
4705
4743
|
}
|
|
4706
4744
|
//#endregion
|