Skip to content
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

Fix o11y timeouts #848

Merged
merged 26 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bin/testObservability/helper/cleanupQueueSync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Sending all the remaining queues for synchronous manner
*/

const RequestQueueHandler = require('./requestQueueHandler');

const shutdown = async () => {
const requestHandler = new RequestQueueHandler();
requestHandler.queue = require(process.argv[2].trim());
await requestHandler.shutdown();
}

shutdown();
2 changes: 2 additions & 0 deletions bin/testObservability/helper/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ exports.OBSERVABILITY_ENV_VARS = [
exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservability/reporter';

exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter');

exports.PENDING_QUEUES_FILE = `pending_queues_${process.pid}.json`;
5 changes: 3 additions & 2 deletions bin/testObservability/helper/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require('fs');
const path = require('path');
const http = require('http');
const https = require('https');
const request = require('request');
const request = require('requestretry');
const { v4: uuidv4 } = require('uuid');
const os = require('os');
const { promisify } = require('util');
Expand Down Expand Up @@ -114,7 +114,8 @@ const nodeRequest = (type, url, data, config) => {
url: `${API_URL}/${url}`,
body: data,
json: config.headers['Content-Type'] === 'application/json',
agent: this.httpsKeepAliveAgent
agent: this.httpsKeepAliveAgent,
maxAttempts: 2
}};

if(url === exports.requestQueueHandler.screenshotEventUrl) {
Expand Down
17 changes: 15 additions & 2 deletions bin/testObservability/helper/requestQueueHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder } = require('./constants');
const { debug, batchAndPostEvents } = require('./helper');
const fs = require('fs');
const cp = require('child_process');
const path = require('path');

const { BATCH_SIZE, BATCH_INTERVAL, PENDING_QUEUES_FILE } = require('./constants');
const { batchAndPostEvents } = require('./helper');

class RequestQueueHandler {
constructor() {
Expand Down Expand Up @@ -48,6 +52,15 @@ class RequestQueueHandler {
}
}

shutdownSync = () => {
this.removeEventBatchPolling('REMOVING');

fs.writeFileSync(path.join(__dirname, PENDING_QUEUES_FILE), JSON.stringify(this.queue));
this.queue = [];
cp.spawnSync('node', [path.join(__dirname, 'cleanupQueueSync.js'), path.join(__dirname, PENDING_QUEUES_FILE)], {stdio: 'inherit'});
fs.unlinkSync(path.join(__dirname, PENDING_QUEUES_FILE));
}
07souravkunda marked this conversation as resolved.
Show resolved Hide resolved

shutdown = async () => {
this.removeEventBatchPolling('REMOVING');
while(this.queue.length > 0) {
Expand Down
4 changes: 4 additions & 0 deletions bin/testObservability/plugin/ipcServer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ipc = require('node-ipc');
const { consoleHolder } = require('../helper/constants');
const { requestQueueHandler } = require('../helper/helper');

exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => {
if (ipc.server) {
Expand All @@ -26,6 +27,9 @@ exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => {
process.on('exit', () => {
unsubscribeServerEvents(ipc.server);
ipc.server.stop();
// Cleaning up all remaining event in request queue handler. Any synchronous operations
// on exit handler will block the process
requestQueueHandler.shutdownSync();
});

});
Expand Down
1 change: 0 additions & 1 deletion bin/testObservability/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ class MyReporter {
}

await this.uploadTestSteps();
await requestQueueHandler.shutdown();
});
}

Expand Down
Loading