dsh-unlag 1.9.15 → 1.9.16

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 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1133,6 +1133,7 @@ function serveBundlesAtCurrentRevision(ctx) {
1133
1133
  const ask = async (url) => {
1134
1134
  let held = null
1135
1135
  let body
1136
+ let failed = false
1136
1137
  if (url !== originalUrl) {
1137
1138
  try {
1138
1139
  req.url = url
@@ -1161,6 +1162,7 @@ function serveBundlesAtCurrentRevision(ctx) {
1161
1162
  try {
1162
1163
  await Promise.resolve(original(req, res))
1163
1164
  } catch (error) {
1165
+ failed = true
1164
1166
  log(`cannot answer a bundle request: ${error?.message ?? error}`)
1165
1167
  } finally {
1166
1168
  try {
@@ -1170,12 +1172,26 @@ function serveBundlesAtCurrentRevision(ctx) {
1170
1172
  /* the response object owns its own shape */
1171
1173
  }
1172
1174
  }
1173
- return { held, body }
1175
+ return { held, body, failed }
1174
1176
  }
1175
1177
  // The table's own answer first: it still holds the generation this page booted from.
1176
1178
  let outcome = await ask(originalUrl)
1177
1179
  if (outcome.held !== null && retargeted !== null) outcome = await ask(retargeted)
1178
- if (outcome.held === null) return undefined
1180
+ if (outcome.held === null) {
1181
+ /**
1182
+ * The table started writing and then failed. A body that already sent its status cannot take
1183
+ * another one, and a socket left open is a document that waits for a script forever; ending it
1184
+ * lets the page see the failure and carry on.
1185
+ */
1186
+ if (outcome.failed === true) {
1187
+ try {
1188
+ if (res.headersSent === true && res.writableEnded !== true && res.destroyed !== true) realEnd.call(res)
1189
+ } catch {
1190
+ /* the response is gone; nothing left to answer */
1191
+ }
1192
+ }
1193
+ return undefined
1194
+ }
1179
1195
  // The shim resolves the set from the address the page asked for, not the retried one.
1180
1196
  try {
1181
1197
  req.url = originalUrl
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unlag",
3
- "version": "1.9.15",
3
+ "version": "1.9.16",
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",