channel-worker 2.5.70 → 2.5.71

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/lib/daemon.js CHANGED
@@ -14,6 +14,12 @@ class Daemon {
14
14
  // Nstbrowser agent of THIS Windows session. On a multi-user box the second
15
15
  // session's agent binds 8849+ because 8848 is taken machine-wide.
16
16
  if (config.nst_api_address) process.env.NST_API_ADDRESS = config.nst_api_address;
17
+ // Tell every NstManager we are pinned to one Windows user's agent, so an
18
+ // unresolved address REFUSES commands instead of defaulting to 8848
19
+ // (= the other session's agent on a multi-user box).
20
+ if (config.nst_agent_user && !config.nst_api_address) {
21
+ process.env.NST_AGENT_PINNED_USER = config.nst_agent_user;
22
+ }
17
23
  this.api = new ApiClient(config.api_url, config.worker_token);
18
24
  this.heartbeat = new Heartbeat(this.api, config.worker_id, 30000, config);
19
25
  this.poller = new JobPoller(this.api, config);
@@ -46,9 +52,16 @@ class Daemon {
46
52
  return;
47
53
  }
48
54
  if (!found) {
49
- if (!quiet) {
55
+ // The pinned user's agent is GONE. Drop a previously resolved address —
56
+ // after a relog the same port can belong to the other session's agent,
57
+ // and driving it opens blank profiles. Fail-closed until it re-appears.
58
+ if (process.env.NST_API_ADDRESS) {
59
+ console.warn(`[daemon] NST agent for "${user}" disappeared `
60
+ + `(was ${process.env.NST_API_ADDRESS}) — refusing NST commands until it is back.`);
61
+ delete process.env.NST_API_ADDRESS;
62
+ } else if (!quiet) {
50
63
  console.warn(`[daemon] No Nstbrowser agent for Windows user "${user}" — `
51
- + 'NST commands will fail until that user is logged in.');
64
+ + 'NST commands are refused (fail-closed) until that user is logged in.');
52
65
  }
53
66
  return;
54
67
  }
@@ -73,7 +86,10 @@ class Daemon {
73
86
  ╚══════════════════════════════════════╝
74
87
  `);
75
88
  console.log(`[daemon] cache server port: ${this.config.cache_port || 8849}`);
76
- console.log(`[daemon] NST agent: ${process.env.NST_API_ADDRESS || 'http://localhost:8848/api/v2 (default)'}`);
89
+ console.log(`[daemon] NST agent: ${process.env.NST_API_ADDRESS
90
+ || (this.config.nst_agent_user
91
+ ? `UNRESOLVED — refusing NST commands until agent of "${this.config.nst_agent_user}" is found`
92
+ : 'http://localhost:8848/api/v2 (default)')}`);
77
93
 
78
94
  // Start local cache server (extension shares this across all profiles)
79
95
  try {
@@ -24,10 +24,31 @@ function nstLaunchError(response, { profileId = '', runningCount = 0 } = {}) {
24
24
  class NstManager {
25
25
  constructor(apiKey, options = {}) {
26
26
  this.apiKey = apiKey;
27
- // Multi-user Windows: each logged-in session runs its OWN Nstbrowser agent,
28
- // and the second one lands on 8849+ because 8848 is already taken machine-wide.
29
- // NST_API_ADDRESS lets a daemon target its own session's agent.
30
- this.baseUrl = options.apiAddress || process.env.NST_API_ADDRESS || 'http://localhost:8848/api/v2';
27
+ this._apiAddress = options.apiAddress || null;
28
+ }
29
+
30
+ // Multi-user Windows: each logged-in session runs its OWN Nstbrowser agent,
31
+ // and the second one lands on 8849+ because 8848 is already taken machine-wide.
32
+ // Resolved at CALL time, not construct time: the daemon's agent watcher
33
+ // rewrites NST_API_ADDRESS whenever ports move, and an instance built before
34
+ // the first resolution must not keep a stale target forever.
35
+ //
36
+ // Fail-closed: when the daemon is pinned to a Windows user
37
+ // (NST_AGENT_PINNED_USER) and that user's agent hasn't been located, REFUSE
38
+ // instead of falling back to 8848 — on a two-session box 8848 is the OTHER
39
+ // user's agent, and opening a profile there starts a blank Chrome: FB shows
40
+ // a login form and fb-guard wrongly flags the account as logged out
41
+ // (35 channels hit 2026-08-31…09-02).
42
+ get baseUrl() {
43
+ if (this._apiAddress) return this._apiAddress;
44
+ if (process.env.NST_API_ADDRESS) return process.env.NST_API_ADDRESS;
45
+ const pinned = process.env.NST_AGENT_PINNED_USER;
46
+ if (pinned) {
47
+ throw new Error(`NST_AGENT_UNRESOLVED: chưa thấy Nstbrowser agent của Windows user "${pinned}" `
48
+ + '— không fallback :8848 (agent của session khác → profile trắng → báo logout oan). '
49
+ + 'Lệnh CHƯA chạm nền tảng; sẽ tự chạy lại khi agent của user đó lên.');
50
+ }
51
+ return 'http://localhost:8848/api/v2';
31
52
  }
32
53
 
33
54
  async api(path, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "channel-worker",
3
- "version": "2.5.70",
3
+ "version": "2.5.71",
4
4
  "description": "Channel Manager worker daemon — runs on remote machines to execute video pipeline jobs",
5
5
  "main": "lib/daemon.js",
6
6
  "bin": {