Skip to content

Commit

Permalink
fix: add rpc endpoint for logging active resources (#160)
Browse files Browse the repository at this point in the history
Adds an temporary endpoint to print out all active handles so we
can see what's not being reclaimed.
  • Loading branch information
achingbrain authored Sep 27, 2024
1 parent 9050153 commit bde4ea1
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 9,024 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ RUN apt-get update && \
WORKDIR /app

COPY package*.json ./
COPY patches ./patches
RUN npm ci --quiet

ENV NODE_ENV production
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ services:
- 4102:4102
- 4001:4001
- 4003:4003
- 9229:9229
environment:
- CONFIG_FLAGS=""
- NODE_OPTIONS="--inspect=0.0.0.0"
volumes:
- ./config.json:/config.json
command: node dist/src/index.js --config /config.json --enable-kademlia --enable-autonat
network_mode: host
command: node --config /config.json --enable-kademlia --enable-autonat --api-host=0.0.0.0

prometheus:
restart: unless-stopped
Expand Down
219 changes: 122 additions & 97 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@
"datastore-level": "^11.0.1",
"libp2p": "^2.1.3",
"prom-client": "^15.1.3",
"uint8arrays": "^5.1.0"
"uint8arrays": "^5.1.0",
"why-is-node-running": "^2.3.0"
},
"devDependencies": {
"aegir": "^44.1.1",
Expand Down
160 changes: 0 additions & 160 deletions patches/@libp2p+prometheus-metrics+4.1.3.patch

This file was deleted.

268 changes: 0 additions & 268 deletions patches/@libp2p+tcp+10.0.5.patch

This file was deleted.

8,482 changes: 0 additions & 8,482 deletions patches/libp2p+2.1.3.patch

This file was deleted.

12 changes: 11 additions & 1 deletion src/create-rpc-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { createServer } from 'node:http'
import { decode } from 'node:querystring'
import { getHeapSnapshot } from 'node:v8'
import { enable } from '@libp2p/logger'
// @ts-expect-error no types
import log from 'why-is-node-running'

export interface RpcServerOptions {
apiPort?: number
Expand Down Expand Up @@ -70,9 +72,17 @@ const resources: Record<string, Record<string, Parameters<typeof createServer>[1
console.info('Enable logging with namespace', query.namespace)
}

// change the logging settings
enable(query.namespace)

// change the logging settings
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('OK')
}
},
'/api/v0/nodejs/handles': {
GET: (req, res) => {
log()

res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('OK')
}
Expand Down
11 changes: 0 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,3 @@ await new Promise<void>((resolve) => metricsServer.listen(metricsPort, '0.0.0.0'
console.info('Metrics server listening', `0.0.0.0:${argMetricsPort}${argMetricsPath}`)

await createRpcServer({ apiPort: parseInt(argApiPort ?? options['api-port'].default, 10), apiHost: argApiHost })

setInterval(() => {
// set a breakpoint on the next line if you want to inspect the running node
node.peerId.toString()

for (const conn of node.getConnections()) {
if (conn.status === 'closed') {
console.info('how did this happen?!')
}
}
}, 5000).unref()

0 comments on commit bde4ea1

Please sign in to comment.