This fixes various corner cases.
This is not motivated by any particular application. However, the server-side code seems at least as simple as the existing client-side code, is more accurate, and removes a potential source of complication from any future work involving asyncs.