From the title I was hoping for this being hacky on the server application side, like how it aborts and clears the memory for a running query.
Still an interesting read. Just wondering, why can't the TCP connection of the query not be used to send a cancellation request? Why does it have the be out of band?
Because Postgres is a very old codebase and was written in a style that assumes there are no threads, and thus there's nothing to listen for a cancellation packet whilst work is getting done. A lot of UNIXes had very poor support for threads for a long time and so this kind of multi-process architecture is common in old codebases.
The TCP URG bit came out of this kind of problem. It triggers a SIGURG signal on UNIX which interrupts the process. Oracle works this way.
These days you'd implement cancellation by having one thread handle inbound messages and another thread do the actual work with shared memory to implement a cooperative cancellation mechanic.
But we should in general have sympathy here. Very little software and very few protocols properly implements any form of cancellation. HTTP hardly does for normal requests, and even if it did, how many web servers abort request processing if the connection drops?
“it is strongly recommended that applications do not employ urgent indications. Nevertheless, urgent indications are still retained as a mandatory part of the TCP protocol to support the few legacy applications that employ them. However, it is expected that even these applications will have difficulties in environments with middleboxes.”
> These days you'd implement cancellation by having one thread handle inbound messages and another thread do the actual work with shared memory to implement a cooperative cancellation mechanic.
Doesn't necessarily need a thread per connection. Could be on an epoll/kqueue/io-uring.
The query would need to periodically re-check a cancellation flag, which has costs and would come with a delay if it's particularly busy.
It isn't really easy to do. A client may send tons of data over the connection, probably data which is calculated by the client as the client's buffer empties. If the server clears the buffers all the time to check for a cancellation it may have quite bad consequences.
I don't know much about postgres, but as I understand it, it's a pretty standard server application. Read a request from the client, work on the request, send the result, read the next request.
Changing that to poll for a cancellation while working is a big change. Also, the server would need to buffer any pipelined requests while looking for a cancellation request. A second connection is not without wrinkles, but it avoids a lot of network complexity.
It's basically got a thread per connection, while it's working on a query that thread isn't listening to incoming traffic on the network socket any more.
Because then the cancellation request would get queued behind any other data that's in flight from the client to the server. In the worst case the TCP buffers are full, and the client cannot even send the request until the server processes some of the existing data that's in-flight.
Hmm, I've been sending receipts straight into Gemini 3 Flash and it handles them just fine. No need for this whole pipeline and definitely MUCH cheaper. Am I missing something?
We make software landscapes understandable and explorable. Our canvas is zoom-to-code, and shows data on overlays from all of the git repos in your company. LLMs go through the codebase and extract the architecture.
We provide clarity when it's most needed: re-orgs, onboarding, explaining the tech stack at board meetings. Or just being stuck in your IDE and want to ask your team mate a question. We'd like to do to large org codebases what Figma did to design.
Comper needs someone that can build revolutionary UIs and go where no man has gone before. Our UI is the core of our product: a zoomable canvas that has all your code, documentation and diagrams on it. We have a long way ahead and need serious thinking to make sure we explain the software stack as simple as can be.
I'm the founder & CTO. We just raised a pre-seed and are now with 6 people. Find the vacancies on our site and send us an email.
Oh this brings back memories. Back in 2007 my dad needed a new Thinkpad which was like 2.5k EUR in NL vs 1k USD in the USA. He also wanted to push his kids to do something adventurous.
So he bought me (19) and little brother (16) tickets to fly from Amsterdam to New York (2x350) and get a cheap hotel for 2 nights (2x100). All to get a Thinkpad W500(?).
We had a great time. Got chased by a wild homeless person on Staten Island who followed us onto the ferry and we were scared stiff. Also walked all over Manhattan. Went to the Bronx but got stared at a lot so quickly went back to the subway. I can still hear the iconic "Stand clear of the Closing Doors" in my head.
Hah, indeed, the story could have happened yesterday. Except maybe thinkpad prices in europe have normalized a bit ;)
What I didn't write is that my feelings towards the USA were 95% positive back then. A bit less after the chase and the Bronx visit, but still. Obama made everything feel hopeful. The current situation is just depressing.
Apart from safety, the rhetoric of the US government regarding the invasion of former allies has led a lot of people to try really hard to boycott as many American products as they can.
I've been using their DNS (and CDN) for a good while. Only positive experiences - fast & rock solid. I would start a new project with them again in future.
I've also tried some of their new more experimental stuff (magic containers, edge scripting) and it's much rougher, but the core product is very good imo.
I wish they'd focus more instead there tbh, there's plenty more that could be done in terms of core content delivery, without trying to enter other (very competitive & I think much more complicated) markets like serverless hosting.
I've been using their DNS (migrating away from Cloudflare) for over a year and I've found it solid. Good latency and fast propagation. Custom nameservers are easy to setup. Migrating from CF is easy too - just export your zonefile from CF and import it to Bunny and you're good to go.
We make software landscapes understandable and explorable. Our canvas is zoom-to-code, and shows data on overlays from all of the git repos in your company. LLMs go through the codebase and extract the architecture.
We provide clarity when it's most needed: re-orgs, onboarding, explaining the tech stack at board meetings. Or just being stuck in your IDE and want to ask your team mate a question. We'd like to do to large org codebases what Figma did to design.
Comper needs someone that can build revolutionary UIs and go where no man has gone before. We are hiring a software engineer and a genius designer (with ideally some engineering prowess). Our UI is the core of our product: a zoomable canvas that has all your code, documentation and diagrams on it. We have a long way ahead and need serious thinking to make sure we explain the software stack as simple as can be.
I'm the founder & CTO. We just raised a pre-seed and are now with 5 people. Find the vacancies on our site and send us an email.
Ok funny anecdote: I once did a special assignment for the CEO of Mendix to build a convertor for MS Access apps to Mendix. So, yes, I can confirm that this is roughly true ;)
And long before that i built an ms-access UI on top of an Oracle 6 database, so yes, MS-Access was one of the client-server era low-code tools. Like powerbuilder, Oracle Forms, etc. (Hi jouke!)
I'm using OVH Cloud for a customer. There's a bit of uncertainty about the CLOUD Act. As OVH has a US subsidiary, they are still doing business in the US and I have seen claims that this makes also their EU offering susceptible to the CLOUD Act. Does anyone know more details?
Still an interesting read. Just wondering, why can't the TCP connection of the query not be used to send a cancellation request? Why does it have the be out of band?