Fixed the RPC client singleton
ci/woodpecker/tag/ociImageTag Pipeline was successful
Details
ci/woodpecker/tag/ociImageTag Pipeline was successful
Details
This commit is contained in:
parent
367257c3ad
commit
53123ce7e8
|
@ -13,11 +13,21 @@ let serial: bigint = BigInt(0);
|
|||
const logger = new Logger("RpcLog");
|
||||
|
||||
async function getRpcClient(): Promise<Socket> {
|
||||
if (client != null) {
|
||||
return client;
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
if (client?.connecting) {
|
||||
client!.once("connect", () => {
|
||||
resolve(client!);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (client != null) {
|
||||
resolve(client);
|
||||
return;
|
||||
}
|
||||
|
||||
client = new Socket();
|
||||
|
||||
const [host, portStr] = config.rpcHost.trim().split(/:(?=[0-9]+$)/, 2);
|
||||
const port = parseInt(portStr);
|
||||
|
||||
|
@ -30,7 +40,6 @@ async function getRpcClient(): Promise<Socket> {
|
|||
|
||||
client.on("connect", () => {
|
||||
exponentialBackoff = 0;
|
||||
resolve(client!);
|
||||
})
|
||||
|
||||
client.on("error", e => {
|
||||
|
@ -49,7 +58,6 @@ async function getRpcClient(): Promise<Socket> {
|
|||
});
|
||||
|
||||
client.on("data", (recv) => {
|
||||
logger.info(`data: ${recv}`);
|
||||
buf.writeBuffer(recv);
|
||||
|
||||
if (buf.length < 1 + 4 + 8) {
|
||||
|
@ -90,8 +98,8 @@ async function getRpcClient(): Promise<Socket> {
|
|||
setTimeout(() => createClient(client!), 1000 * (1 + Math.pow(1.5, exponentialBackoff)));
|
||||
};
|
||||
|
||||
client = new Socket();
|
||||
createClient(client);
|
||||
createClient(client!);
|
||||
resolve(client!);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ export default async (job: Bull.Job<DeliverJobData>) => {
|
|||
}
|
||||
|
||||
// 5xx etc.
|
||||
throw new Error(`${err.retry_class} ${err.kind}: ${err.message}`);
|
||||
throw new Error(`${err.retry_class}: ${err.message}`);
|
||||
} else {
|
||||
throw res;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue