dsh-unlag 1.9.37 → 1.9.38

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.
Files changed (2) hide show
  1. package/index.js +18 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -106,6 +106,18 @@ const MAX_TOTAL_SCRIPT_BYTES = 32 * 1024 * 1024
106
106
  * is work the request itself must not be able to grow without bound.
107
107
  */
108
108
  const MAX_BUNDLE_IDS = 128
109
+ /**
110
+ * How long one stale-bundle answer may spend before it gives the request back to the app's own
111
+ * route. Each row is bounded on its own, but a request can name many rows and the route answers
112
+ * whatever a socket asks: without a whole-request bound one made-up address holds a connection for
113
+ * as long as its rows add up.
114
+ */
115
+ const MAX_ANSWER_MS = 15_000
116
+ /** The same bound for a test that must reach it quickly. */
117
+ function answerBudgetMs() {
118
+ const set = Number(process.env.DSH_UNLAG_STALE_MS ?? '')
119
+ return set > 0 ? set : MAX_ANSWER_MS
120
+ }
109
121
  /**
110
122
  * How long one startup check may spend reading the list. Each address is bounded on its own, but a
111
123
  * list of them is not: dozens of slow addresses would otherwise hold a press past the moment the
@@ -974,10 +986,11 @@ async function currentEntryBody(clientModules, graph, id) {
974
986
  * answering with them in the requested order registers exactly the plugins the document expects,
975
987
  * so a boot that would otherwise 404 and end the app comes up instead.
976
988
  */
977
- async function regroupedBundleAnswer(clientModules, graph, request) {
989
+ async function regroupedBundleAnswer(clientModules, graph, request, deadline = Date.now() + answerBudgetMs()) {
978
990
  if (request.sourceMap) return null
979
991
  const parts = []
980
992
  for (const id of request.ids) {
993
+ if (Date.now() > deadline) return null
981
994
  const body = await currentEntryBody(clientModules, graph, id)
982
995
  if (body === null) return null
983
996
  parts.push(body)
@@ -1005,7 +1018,7 @@ async function regroupedBundleAnswer(clientModules, graph, request) {
1005
1018
  * booting from an old startup list that meets one ends the whole app: a boot that comes up without
1006
1019
  * a plugin it no longer has beats that.
1007
1020
  */
1008
- async function survivingBundleAnswer(clientModules, graph, request) {
1021
+ async function survivingBundleAnswer(clientModules, graph, request, deadline = Date.now() + answerBudgetMs()) {
1009
1022
  if (request.sourceMap) return null
1010
1023
  const entries = Array.isArray(graph?.entries) ? graph.entries : []
1011
1024
  const served = new Set(entries.filter((row) => typeof row?.id === 'string').map((row) => row.id))
@@ -1013,6 +1026,7 @@ async function survivingBundleAnswer(clientModules, graph, request) {
1013
1026
  if (gone.length === 0) return null
1014
1027
  const parts = []
1015
1028
  for (const id of request.ids) {
1029
+ if (Date.now() > deadline) return null
1016
1030
  if (served.has(id)) {
1017
1031
  const body = await currentEntryBody(clientModules, graph, id)
1018
1032
  if (body === null) return null
@@ -1031,7 +1045,7 @@ async function survivingBundleAnswer(clientModules, graph, request) {
1031
1045
  * that really contains every plugin it claims is handed back; anything unsure answers null, so the
1032
1046
  * route then behaves exactly as before and an unknown id still ends as a plain 404.
1033
1047
  */
1034
- async function currentBundleAnswer(clientModules, method, url) {
1048
+ async function currentBundleAnswer(clientModules, method, url, deadline = Date.now() + answerBudgetMs()) {
1035
1049
  const request = bundleRequest(url)
1036
1050
  if (request === null) return null
1037
1051
  const graph = clientModules.graph()
@@ -1057,7 +1071,7 @@ async function currentBundleAnswer(clientModules, method, url) {
1057
1071
  }
1058
1072
  }
1059
1073
  }
1060
- return (await regroupedBundleAnswer(clientModules, graph, request)) ?? survivingBundleAnswer(clientModules, graph, request)
1074
+ return (await regroupedBundleAnswer(clientModules, graph, request, deadline)) ?? survivingBundleAnswer(clientModules, graph, request, deadline)
1061
1075
  }
1062
1076
 
1063
1077
  /** Answer one stale request over the plain request/response route an app registers. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unlag",
3
- "version": "1.9.37",
3
+ "version": "1.9.38",
4
4
  "type": "module",
5
5
  "description": "A press applies plugin edits right away and brings a laggy interface back; automatic reloading stays off unless you turn it on, so the press is the only trigger, and nothing restarts.",
6
6
  "license": "MIT",