Description
Hello there, I am sorry in advance for the lack of knowledge/information about the problems I am facing but I'm coming here to mostly get help in digging this further in hope to return the favor back by helping find/fix a bug...
Here's the context:
- Mockttp is used in an app that crawls the web using chromium with --proxy-server switch.
- We use mockttp as a mitm proxy to see requests/responses.
- The app is running between 20 to 60 chromium instances, are all connecting to the proxy.
- The pages visited by the chromium instances are polling in xhr POST some data every second.
- Everything happens on the same domain, with rules set for that particular domain.
At some points, the chromium instances will stop being able to connect, the xhr requests being stuck at connecting. I am not sure if this part is about connecting to the proxy or the upstream.
I've seen it happen a couple times, sometimes 5 minutes after starting the app, sometimes it would be able to run half a day.
I don't see any errors on the node console which makes me really hesitant as to where to problem comes from. Listening on tls-client-error and client-error produces no logs either.
To make sure this was not related with other parts of the app, when the server stops responding to the chromium instances, I opened up a chrome window with the proxy set up and I could access other websites but not the targeted domain in HTTPS. The domain was still working on HTTP but not https which makes me believe it is something regarding TLS.
On a side note, we get rare ERR_HTTP2_PROTOCOL_ERROR errors on the chromium side. I am not sure if this is linked in any means but when we do receive this error, the next requests continue working.
Here's the code we are using:
const mockServer = getLocal({
http2: true,
suggestChanges: false,
recordTraffic: false,
debug: true,
https: {
keyPath: "./testCA.key",
certPath: "./testCA.pem",
},
});
const beforeRequest = (req: CompletedRequest) => {
const ua = req.headers["user-agent"].split("]");
req.tags[0] = ua[0];
const headers = req.headers;
headers["user-agent"] = ua[1];
return {
headers,
};
};
mockServer
.forAnyRequest()
.forHost("x.com")
.withUrlMatching(/\.cgi$/)
.thenPassThrough({
beforeRequest,
beforeResponse: (res, req) => {
try {
res.body
.getText()
.then((b) => {
const agent = Arbiter.agents.get(req.tags[0]);
if (!agent) {
console.error("Agent not found", req.tags[0], req);
return;
}
agent.on('response',b);
})
.catch(console.error);
} catch (e) {
console.error(e);
}
},
});
mockServer
.forUnmatchedRequest()
.forHost("x.com")
.thenPassThrough({
beforeRequest,
});
mockServer.forUnmatchedRequest().thenPassThrough();
Please note that debug was not turned on until 1 hours ago. And since then, the proxy has been working very fine. I will report back if the debug logs provide anything when a problem arises.