Skip to content

restate-sdk-clients Provide request timeout option #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mupperton opened this issue Oct 9, 2024 · 1 comment · Fixed by #451
Closed

restate-sdk-clients Provide request timeout option #445

mupperton opened this issue Oct 9, 2024 · 1 comment · Fixed by #451
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@mupperton
Copy link
Contributor

Currently there does not seem to be a way of configuring a timeout on invoking a handler from the restate-sdk-clients package

E.g.

await connect({ url: 'http://restate-server-url' }).serviceClient({ name: 'svc' }).myHandler()

In a restate-service you can do this with .orTimeout() on the end

So these requests appear to just hang forever (if there is a temporary issue on the handler for example) until the invocation resolves

@igalshilman
Copy link
Contributor

Hey @mupperton, this is definitly doable.

under the hood we are just using fetch, so it should be possible to pass trough a timeout (or more generally an AbortSignal) trough the rpc options.

Maybe an API like that:

serviceClient(...).myHandler("foo", restate.rpc.opts({ timeout: 123 }))

Also, note that these are normal promises (not restate promises) that are coming from wrapping fetch so you can also use the regular node js promise combinators. For example here is how to add a timeout for a promise:

(source: https://stackoverflow.com/a/46675277)

const withTimeout = (millis, promise) => {
    let timeoutPid;
    const timeout = new Promise((resolve, reject) =>
        timeoutPid = setTimeout(
            () => reject(`Timed out after ${millis} ms.`),
            millis));
    return Promise.race([
        promise,
        timeout
    ]).finally(() => {
        if (timeoutPid) {
            clearTimeout(timeoutPid);
        }
    });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants