Skip to content

Commit

Permalink
Merge pull request #256 from matrix-org/hs/cleartimeout-on-ping
Browse files Browse the repository at this point in the history
Clear the timeout for a self ping after getting a response
  • Loading branch information
Half-Shot authored Oct 21, 2020
2 parents 192d1e4 + efb791d commit 3d25f4d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/256.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add function to ping the homeserver to check that the AS can be reached
1 change: 1 addition & 0 deletions src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ export class Bridge {
sentTs,
});
await this.selfPingDeferred.defer.promise;
clearTimeout(this.selfPingDeferred.timeout);
return Date.now() - sentTs;
}

Expand Down
11 changes: 7 additions & 4 deletions src/components/membership-queue.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Bridge } from "../bridge";
import { Request } from "./request";
import { get as getLogger } from "./logging";
import PQueue from "p-queue";

const log = getLogger("MembershipQueue");

export interface ThinRequest {
getId(): string;
}

interface QueueUserItem {
type: "join"|"leave";
kickUser?: string;
Expand All @@ -13,7 +16,7 @@ interface QueueUserItem {
roomId: string;
userId: string;
retry: boolean;
req: Request<unknown>;
req: ThinRequest;
}

export interface MembershipQueueOpts {
Expand Down Expand Up @@ -54,7 +57,7 @@ export class MembershipQueue {
* @param req The request entry for logging context
* @param retry Should the request retry if it fails
*/
public async join(roomId: string, userId: string|undefined, req: Request<unknown>, retry = true) {
public async join(roomId: string, userId: string|undefined, req: ThinRequest, retry = true) {
return this.queueMembership({
roomId,
userId: userId || this.bridge.botUserId,
Expand All @@ -74,7 +77,7 @@ export class MembershipQueue {
* @param reason Reason for leaving/kicking
* @param kickUser The user to be kicked. If left blank, this will be a leave.
*/
public async leave(roomId: string, userId: string, req: Request<unknown>,
public async leave(roomId: string, userId: string, req: ThinRequest,
retry = true, reason?: string, kickUser?: string) {
return this.queueMembership({
roomId,
Expand Down

0 comments on commit 3d25f4d

Please sign in to comment.