-
Notifications
You must be signed in to change notification settings - Fork 15
lib,src,test: fix race during tracing toggles #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
santigimeno
wants to merge
2
commits into
node-v24.x-nsolid-v6.x
Choose a base branch
from
santi/tracing_crash_enable_disable
base: node-v24.x-nsolid-v6.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+249
−18
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
test/addons/nsolid-tracing/test-otel-fetch-enable-disable-race.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Flags: --dns-result-order=ipv4first | ||
| 'use strict'; | ||
|
|
||
| const common = require('../../common'); | ||
| const assert = require('assert'); | ||
| const http = require('http'); | ||
| const { once } = require('events'); | ||
|
|
||
| const bindingPath = require.resolve(`./build/${common.buildType}/binding`); | ||
| const binding = require(bindingPath); | ||
|
|
||
| const concurrency = 16; | ||
| const fetchRounds = 150; | ||
| const toggleRounds = 400; | ||
|
|
||
| async function main() { | ||
| binding.skipExpectedTracesCheck(); | ||
| binding.setupTracing(binding.kSpanHttpClient); | ||
|
|
||
| const server = http.createServer((req, res) => { | ||
| req.resume(); | ||
| res.writeHead(200, { 'content-type': 'text/plain' }); | ||
| setImmediate(() => res.end('ok')); | ||
| }); | ||
|
|
||
| server.listen(0, '127.0.0.1'); | ||
| await once(server, 'listening'); | ||
| const { port } = server.address(); | ||
| const url = `http://127.0.0.1:${port}/`; | ||
|
|
||
| const failures = []; | ||
|
|
||
| async function runFetches() { | ||
| for (let i = 0; i < fetchRounds; i++) { | ||
| const batch = Array.from({ length: concurrency }, async () => { | ||
| try { | ||
| const res = await fetch(url, { | ||
| method: 'POST', | ||
| body: 'payload', | ||
| }); | ||
| await res.text(); | ||
| } catch (err) { | ||
| failures.push(err); | ||
| } | ||
| }); | ||
| await Promise.all(batch); | ||
| } | ||
| } | ||
|
|
||
| async function toggleTracing() { | ||
| for (let i = 0; i < toggleRounds; i++) { | ||
| binding.stopTracing(); | ||
| await new Promise(setImmediate); | ||
| binding.setupTracing(binding.kSpanHttpClient); | ||
| await new Promise(setImmediate); | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| await Promise.all([ | ||
| runFetches(), | ||
| toggleTracing(), | ||
| ]); | ||
| } finally { | ||
| binding.stopTracing(); | ||
| server.close(); | ||
| await once(server, 'close'); | ||
| } | ||
|
|
||
| assert.deepStrictEqual(failures, []); | ||
| } | ||
|
|
||
| main().then(common.mustCall()).catch((err) => { | ||
| throw err; | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Flags: --expose-internals | ||
| import { mustCall, mustSucceed } from '../common/index.mjs'; | ||
| import { | ||
| checkExitData, | ||
| GRPCServer, | ||
| TestClient, | ||
| } from '../common/nsolid-grpc-agent/index.js'; | ||
|
|
||
| const traceBursts = 100; | ||
| const toggleRounds = 20; | ||
|
|
||
| async function runRepro(getEnv, kind) { | ||
| return new Promise((resolve, reject) => { | ||
| const grpcServer = new GRPCServer(); | ||
| grpcServer.start(mustSucceed(async (port) => { | ||
| const env = getEnv(port); | ||
| const opts = { | ||
| stdio: ['inherit', 'inherit', 'inherit', 'ipc'], | ||
| env, | ||
| }; | ||
|
|
||
| const client = new TestClient([], opts); | ||
| const agentId = await client.id(); | ||
|
|
||
| grpcServer.on('exit', mustCall((data) => { | ||
| checkExitData(data.msg, data.metadata, agentId, { code: 0, error: null, profile: '' }); | ||
| grpcServer.close(); | ||
| resolve(); | ||
| })); | ||
|
|
||
| // send lots of trace requests to trigger tracing | ||
| for (let i = 0; i < traceBursts; i++) { | ||
| client.tracing(kind, 0); | ||
| } | ||
|
|
||
| // toggle tracing on and off | ||
| for (let i = 0; i < toggleRounds; i++) { | ||
| const enabled = (i % 2) !== 0; | ||
| await grpcServer.reconfigure(agentId, { tracingEnabled: enabled }); | ||
| } | ||
|
|
||
| await client.shutdown(); | ||
| })); | ||
| }); | ||
| } | ||
|
|
||
| const tests = []; | ||
| tests.push({ | ||
| name: 'should reproduce fetch tracing crash via grpc reconfigure', | ||
| test: async (getEnv) => runRepro(getEnv, 'fetch'), | ||
| }); | ||
|
|
||
| tests.push({ | ||
| name: 'should reproduce http tracing crash via grpc reconfigure', | ||
| test: async (getEnv) => runRepro(getEnv, 'http'), | ||
| }); | ||
|
|
||
| const testConfigs = [ | ||
| { | ||
| getEnv: (port) => ({ | ||
| NODE_DEBUG_NATIVE: 'nsolid_grpc_agent', | ||
| NSOLID_GRPC_INSECURE: 1, | ||
| NSOLID_GRPC: `localhost:${port}`, | ||
| NSOLID_TRACING_ENABLED: 1, | ||
| NSOLID_INTERVAL: 100000, | ||
| }), | ||
| }, | ||
| ]; | ||
|
|
||
| for (const testConfig of testConfigs) { | ||
| for (const { name, test } of tests) { | ||
| console.log(`[tracing] ${name}`); | ||
| await test(testConfig.getEnv); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.