When a @motherduck/wasm-client connection is initialized without a token / with an invalid token (as can happen in reactive notebooks), the client will continuously hammer https://api.motherduck.com/sessions.CreateShortLivedTokenService/CreateShortLivedToken and receive 401 responses. How can I stop it from doing that and preferably reinitialize the connection without having to reload the page?
Hey Fabian, is this with Observable as mentioned in previous threads, or something you're building?
Yep, Observable (although I'd expect it to repro in other environments)
Looks like getAsyncDuckDb always returns a singleton promise (which has no setter exposed), so my only chance would be to somehow break the loop (and even then I probably couldn't reinitialize)
Thanks for raising this! This appears to be a known issue and I've raised your use-case internally. We might have a workaround coming soon -- I will keep you posted. Today, the only workaround is to reload the webpage. Does this unblock you for now?
I can probably make do since I can delay the create() call until a token has been provided. I might also look into loading the worker directly
... I'm good now. 👍 This loads the extension directly and terminates the worker on auth errors: https://observablehq.com/@mootari/motherduck
... Streaming seems to work as well after I dropped an obsolete monkeypatch for PIVOT. Although duckdb buffers way too many results and then streams the rest rather slowly, which may suggest a watermark issue.
I'm also seeing a few "unassociated response" warnings for MD_EVENT (with "CatalogChangeEvent"), which I assume would have been handled by Motherduck's bundle. All in all this is clearly only a stopgap solution, and I'm eager to see how new releases of the wasm client will fare.
Just in case it's helpful (if not, no worries), these are the batch timings that I get for 6M rows with the above implementation. It seems that the client buffers the entire result set before passing it on. The narrow timing here also suggests that any streaming issues in Observable's data tables may be caused by the table implementation, not the MD backend. (And fwiw, I'm fully aware that this use case is likely unsupported; I'm mostly documenting things for myself)
Glad to see you're unblocked for now.
Noah S. Thanks for the update, but as far as I can tell the method has been around since 1.5.2-r.1 (just undocumented) and requires a successful prior connection. An instance that fails to authenticate can still not be cleaned up and will continue to spam CreateShortLivedToken requests that 401.
.png)