pizza3927
pizza39272d ago

Query via a non-connected wsLink never times out despite AbortSignal

When the wsLink is disconnected (eg server not available), is it normal that a query does not timeout despite passing an AbortSignal ? I was not expecting this behavior. Is there an easy workaround for this?
import { createTRPCClient, createWSClient, wsLink } from "@trpc/client";

const link = wsLink<Router>({
client: createWSClient({ url: TRPC_SERVER_URL }),
});
const client = createTRPCClient<Router>({
links: [link],
});

// assuming the trpc server is up and running
client.hello
.query({ name: "world" }, { signal: AbortSignal.timeout(1) })
.finally(() => console.log(`done`))
// >> logs 'done'

// assuming instance1 is not available and the ws link is disconnected
client.hello
.query({ name: "world" }, { signal: AbortSignal.timeout(1) })
.finally(() => console.log(`done`))
// >> .... [hangs forever, does not time out despite AbortSignal]
import { createTRPCClient, createWSClient, wsLink } from "@trpc/client";

const link = wsLink<Router>({
client: createWSClient({ url: TRPC_SERVER_URL }),
});
const client = createTRPCClient<Router>({
links: [link],
});

// assuming the trpc server is up and running
client.hello
.query({ name: "world" }, { signal: AbortSignal.timeout(1) })
.finally(() => console.log(`done`))
// >> logs 'done'

// assuming instance1 is not available and the ws link is disconnected
client.hello
.query({ name: "world" }, { signal: AbortSignal.timeout(1) })
.finally(() => console.log(`done`))
// >> .... [hangs forever, does not time out despite AbortSignal]
BTW thanks a lot for this awesome library. Really incredible work.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?