@metric-im/administrate 1.1.7 → 1.1.8

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/multisite.mjs +20 -5
  2. package/package.json +1 -1
package/multisite.mjs CHANGED
@@ -15,6 +15,7 @@ export class MultiSite {
15
15
  this.app = app;
16
16
  this.options = options || {};
17
17
  this.sites = {};
18
+ this.spawning = new Set(); // Track domains currently being spawned
18
19
  this._spawnPort = (parseInt(this.options.spawnPort||0) || 53874);
19
20
  this.usedPorts = new Set();
20
21
  this.healthCheckIntervals = new Map();
@@ -325,11 +326,25 @@ export class MultiSite {
325
326
  res.status(502).send('Bad Gateway. Try reloading.');
326
327
  }
327
328
  } else {
328
- this.sites[domain] = Site.Clone(domain,this);
329
- // Retry the request after spawning
330
- setTimeout(() => {
331
- res.redirect(`//${req.hostname}${req.url}`);
332
- }, 2000);
329
+ // Check if already spawning to prevent race condition
330
+ if (this.spawning.has(domain)) {
331
+ // Site is already being spawned, wait for it
332
+ setTimeout(() => {
333
+ res.redirect(`//${req.hostname}${req.url}`);
334
+ }, 2000);
335
+ } else {
336
+ // Mark as spawning
337
+ this.spawning.add(domain);
338
+ this.sites[domain] = Site.Clone(domain,this);
339
+ // Remove from spawning set after spawn completes
340
+ setTimeout(() => {
341
+ this.spawning.delete(domain);
342
+ }, 3000);
343
+ // Retry the request after spawning
344
+ setTimeout(() => {
345
+ res.redirect(`//${req.hostname}${req.url}`);
346
+ }, 2000);
347
+ }
333
348
  }
334
349
  });
335
350
  return router;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metric-im/administrate",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "Tools for site administration",
5
5
  "homepage": "https://github.com/metric-im/administrate#readme",
6
6
  "bugs": {