Skip to content

Commit

Permalink
fix: Session with given id not found(closes #7865, #7810) (#7897)
Browse files Browse the repository at this point in the history
## Purpose
The second part of #7875
We handled the Request error, but we have an unsafe code in
targetAttached handler.

## Approach
Use try-catch 

## References
#7875

## Pre-Merge TODO
- [ ] Write tests for your proposed changes
- [ ] Make sure that existing tests do not fail
  • Loading branch information
Artem-Babich committed Jul 24, 2023
1 parent 6ce7404 commit acfcf19
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/native-automation/request-pipeline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ import {
import NativeAutomationPipelineContext from '../request-hooks/pipeline-context';
import { NativeAutomationInitOptions } from '../../shared/types';
import getSpecialRequestHandler from './special-handlers';
import { safeContinueRequest, safeContinueResponse } from './safe-api';
import {
connectionResetGuard,
safeContinueRequest,
safeContinueResponse,
} from './safe-api';
import NativeAutomationApiBase from '../api-base';
import { resendAuthRequest } from './resendAuthRequest';
import TestRunBridge from './test-run-bridge';
Expand Down Expand Up @@ -402,13 +406,17 @@ export default class NativeAutomationRequestPipeline extends NativeAutomationApi
if (!isIFrame && !isWorker)
return;

// @ts-ignore
await this._client.Runtime.runIfWaitingForDebugger(event.sessionId);

if (isIFrame) {
await connectionResetGuard(async () => {
// @ts-ignore
await this._client.Fetch.enable({ patterns: ALL_REQUESTS_DATA }, event.sessionId);
}
await this._client.Runtime.runIfWaitingForDebugger(event.sessionId);

if (isIFrame) {
// @ts-ignore
await this._client.Fetch.enable({ patterns: ALL_REQUESTS_DATA }, event.sessionId);
}
}, err => {
requestPipelineLogger(`Unhandled error %s during processing %s`, err, event);
});
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/native-automation/request-pipeline/safe-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const IGNORED_ERROR_CODES = {
SESSION_WITH_GIVEN_ID_NOT_FOUND: -32001,
};

async function connectionResetGuard (handleRequestFn: () => Promise<void>, handleErrorFn: (err: any) => void): Promise<void> {
export async function connectionResetGuard (handleRequestFn: () => Promise<void>, handleErrorFn: (err: any) => void): Promise<void> {
try {
await handleRequestFn();
}
Expand Down

0 comments on commit acfcf19

Please sign in to comment.