@lde/distribution-probe 0.2.4 → 0.2.6

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/dist/probe.js +15 -10
  2. package/package.json +1 -1
package/dist/probe.js CHANGED
@@ -734,12 +734,12 @@ async function validateBody(body, contentType, baseIRI, budgetSignal, truncated)
734
734
  * Parse an RDF body just far enough to tell whether it carries any triples:
735
735
  * resolve on the first triple (presence is all we need, not a full count), on a
736
736
  * clean end with none ('empty'), or on a parse error. The parse is bounded by
737
- * `budgetSignal` – the caller's validation-budget {@link AbortController} –
737
+ * `budgetSignal` – the caller’s validation-budget {@link AbortController} –
738
738
  * because a JSON-LD `@context` is fetched from its origin, and a slow or hanging
739
739
  * context host would otherwise stall the probe past its budget; on abort – and
740
740
  * likewise when a remote `@context` is unreachable – the outcome is
741
741
  * 'inconclusive', so a valid distribution is never flagged faulty for a context
742
- * host's failure. Sharing the caller's single budget (rather than starting a
742
+ * host’s failure. Sharing the caller’s single budget (rather than starting a
743
743
  * second, identical timer) keeps that timeout deterministic: it fires once, when
744
744
  * the budget elapses, instead of leaving an orphan timer to settle on its own
745
745
  * schedule. `baseIRI` resolves any relative IRIs in the document.
@@ -765,20 +765,25 @@ function classifyRdfBody(body, contentType, baseIRI, budgetSignal, truncated) {
765
765
  quads.destroy();
766
766
  resolve(outcome);
767
767
  }
768
- // The budget may already have elapsed while the body was being read; treat an
769
- // already-aborted signal as an immediate expiry rather than waiting for an
770
- // 'abort' event that will never come.
771
- if (budgetSignal.aborted) {
772
- onBudgetElapsed();
773
- return;
774
- }
775
- budgetSignal.addEventListener('abort', onBudgetElapsed, { once: true });
768
+ // Attach the parser listeners before consulting the budget: settle() calls
769
+ // quads.destroy(), which can make the parser emit a late 'error', so the
770
+ // error sink must already be in place – including on the already-aborted
771
+ // path below – or that error goes unhandled and crashes the process.
776
772
  quads
777
773
  .on('data', () => settle({ type: 'hasTriples' }))
778
774
  .on('error', (error) => settle(truncated || isRemoteContextError(error)
779
775
  ? { type: 'inconclusive' }
780
776
  : { type: 'parseError', message: error.message }))
781
777
  .on('end', () => settle(truncated ? { type: 'inconclusive' } : { type: 'empty' }));
778
+ // The budget may already have elapsed while the body was being read; an
779
+ // already-aborted signal never emits another 'abort', so settle immediately
780
+ // rather than wait for an event that will not come.
781
+ if (budgetSignal.aborted) {
782
+ onBudgetElapsed();
783
+ }
784
+ else {
785
+ budgetSignal.addEventListener('abort', onBudgetElapsed, { once: true });
786
+ }
782
787
  });
783
788
  }
784
789
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lde/distribution-probe",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/ldelements/lde.git",
6
6
  "directory": "packages/distribution-probe"