whatap 2.0.0 → 2.0.1-canary.0

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/core/agent.js CHANGED
@@ -200,19 +200,14 @@ NodeAgent.prototype.writeToFile = function(home, fileName, value) {
200
200
  }
201
201
  };
202
202
 
203
- // Modified isGoAgentRunning to check PID +-1 range
203
+ // Verify the recorded PID corresponds to a live whatap_nodejs process.
204
+ // Go agent writes its real (post-daemon-fork) PID into the shared PID file,
205
+ // so we trust that value directly instead of guessing adjacent PIDs.
204
206
  NodeAgent.prototype.isGoAgentRunning = function(pid) {
205
207
  try {
206
208
  if (!pid) return false;
207
209
 
208
- // 원래 PID와 +1, -1된 PID 모두 확인
209
- const pidsToCheck = [
210
- parseInt(pid),
211
- parseInt(pid) + 1,
212
- parseInt(pid) - 1
213
- ];
214
-
215
- // Logger.print("WHATAP-007", `Checking PIDs: ${pidsToCheck.join(', ')} (original: ${pid})`, false);
210
+ const pidsToCheck = [parseInt(pid)];
216
211
 
217
212
  for (const pidToCheck of pidsToCheck) {
218
213
  try {
@@ -623,6 +618,24 @@ NodeAgent.prototype.updateConfig = function(home, optKey, optValue) {
623
618
  }
624
619
  };
625
620
 
621
+ /**
622
+ * Detect whether this process is running inside a container (Docker / K8s).
623
+ * In container environments, the Go agent should run in foreground mode so that
624
+ * Node.js can directly manage the child process lifecycle (no orphan/zombie risk).
625
+ */
626
+ NodeAgent.prototype.isContainerEnvironment = function() {
627
+ if (process.platform !== 'linux') return false;
628
+
629
+ try {
630
+ if (fs.existsSync('/.dockerenv')) return true;
631
+ if (fs.existsSync('/run/.containerenv')) return true;
632
+ } catch (e) {}
633
+
634
+ if (process.env.KUBERNETES_SERVICE_HOST) return true;
635
+
636
+ return false;
637
+ };
638
+
626
639
  /**
627
640
  * Detect Node.js cluster mode and set environment variables
628
641
  * This allows Node.js cluster to work the same way as PM2 cluster mode
@@ -775,6 +788,14 @@ NodeAgent.prototype.startHealthCheck = function() {
775
788
  clearInterval(self._healthCheckInterval);
776
789
  }
777
790
 
791
+ // In container environments the Go agent runs in foreground, so Node.js
792
+ // already tracks its lifecycle via ChildProcess events. Polling is redundant
793
+ // and historically caused false-positive restart loops -> orphan zombies.
794
+ if (self.isContainerEnvironment()) {
795
+ Logger.print("WHATAP-223", "Container environment detected, skipping periodic health check (foreground mode handles lifecycle)", false);
796
+ return;
797
+ }
798
+
778
799
  // PM2 cluster 모드에서는 첫 번째 인스턴스만 health check 수행
779
800
  const isPM2Cluster = self.isPM2ClusterMode();
780
801
  if (isPM2Cluster && process.env.pm_id !== '0') {
@@ -1119,10 +1140,18 @@ NodeAgent.prototype.startGoAgent = function(opts = {}) {
1119
1140
 
1120
1141
  // 에이전트 프로세스 시작
1121
1142
  // Windows: -t 2 foreground (detached 모드)
1122
- // Unix/Linux: -t 2 -d 1 (daemon 모드)
1143
+ // Linux container: -t 2 (foreground, Node.js가 직접 관리)
1144
+ // Linux VM/베어메탈: -t 2 -d 1 (daemon 모드, 기존 호환)
1145
+ const isContainer = this.isContainerEnvironment();
1123
1146
  const spawnArgs = platform === 'win32'
1124
1147
  ? ['-t', '2', 'foreground']
1125
- : ['-t', '2', '-d', '1'];
1148
+ : isContainer
1149
+ ? ['-t', '2']
1150
+ : ['-t', '2', '-d', '1'];
1151
+
1152
+ if (isContainer) {
1153
+ Logger.print("WHATAP-224", "Container environment: starting Go agent in foreground mode", false);
1154
+ }
1126
1155
 
1127
1156
  const spawnOptions = {
1128
1157
  cwd: whatapHome,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "whatap",
3
3
  "homepage": "http://www.whatap.io",
4
- "version": "2.0.0",
5
- "releaseDate": "20260427",
4
+ "version": "2.0.1-canary.0",
5
+ "releaseDate": "20260526",
6
6
  "description": "Monitoring and Profiling Service",
7
7
  "main": "index.js",
8
8
  "scripts": {},
@@ -1,14 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(grep -n \"ECONNREFUSED\" /Users/seunghunlee/agent_workspace/nodejs_agent/lib/observers/*.js /Users/seunghunlee/agent_workspace/nodejs_agent/lib/core/agent.js 2>/dev/null)",
5
- "WebSearch",
6
- "Bash(go env *)",
7
- "Bash(ls -l \"$\\(go env GOPATH\\)/bin/govulncheck\")",
8
- "Bash(brew list *)",
9
- "Bash(brew search *)",
10
- "Bash(brew info *)",
11
- "Bash(echo \"--- exit $? ---\")"
12
- ]
13
- }
14
- }