Skip to content

Commit

Permalink
Fix abort error
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Jul 13, 2023
1 parent 68c5e2e commit ba6b116
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 7 additions & 1 deletion packages/api/src/beacon/server/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ChainForkConfig} from "@lodestar/config";
import {ErrorAborted} from "@lodestar/utils";
import {Api, ReqTypes, routesData, getEventSerdes} from "../routes/events.js";
import {ServerRoutes} from "../../utils/server/index.js";
import {ServerApi} from "../../interfaces.js";
Expand Down Expand Up @@ -49,7 +50,12 @@ export function getRoutes(config: ChainForkConfig, api: ServerApi<Api>): ServerR
// The client may disconnect and we need to clean the subscriptions.
req.raw.once("close", () => resolve());
req.raw.once("end", () => resolve());
req.raw.once("error", (err) => reject(err));
req.raw.once("error", (err) => {
if ("code" in err && (err as unknown as {code: string}).code === "ECONNRESET") {
return reject(new ErrorAborted());
}
return reject(err);
});
});

// api.eventstream will never stop, so no need to ever call `res.raw.end();`
Expand Down
5 changes: 1 addition & 4 deletions packages/beacon-node/src/api/rest/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ export class RestApiServer {

private status = Status.Closed;

constructor(
private readonly opts: RestApiServerOpts,
modules: RestApiServerModules
) {
constructor(private readonly opts: RestApiServerOpts, modules: RestApiServerModules) {
// Apply opts defaults
const {logger, metrics} = modules;

Expand Down

0 comments on commit ba6b116

Please sign in to comment.