Skip to content

Guard against stale markers in async callbacks#281

Open
benthamite wants to merge 2 commits intokidd:masterfrom
benthamite:fix/guard-stale-markers
Open

Guard against stale markers in async callbacks#281
benthamite wants to merge 2 commits intokidd:masterfrom
benthamite:fix/guard-stale-markers

Conversation

@benthamite
Copy link
Copy Markdown

@benthamite benthamite commented Mar 21, 2026

Summary

When a buffer is killed while an async HTTP request is in flight, markers pointing into that buffer become stale (marker-buffer returns nil). Every with-current-buffer (marker-buffer marker) and org-with-point-at marker call in a deferred callback then signals an error because set-buffer receives nil, producing a confusing "Wrong type argument: bufferp, nil".

This occasionally happens during org-gcal-sync in my experience.

  • Add a marker-buffer nil check to org-gcal--with-point-at-no-widen macro
  • Add guards before marker use in org-gcal--sync-update-entries, org-gcal--post-event (HTTP 412 and success callbacks), org-gcal--delete-event (HTTP 412 callback), and org-gcal-delete-at-point (:finally callback)
  • Each guard signals a descriptive error that the existing deferred:error handlers catch and log gracefully

Test plan

  • Byte-compiles without new warnings
  • Trigger org-gcal-sync and kill the calendar buffer while the sync is running — should log a message instead of erroring with "Wrong type argument: bufferp, nil"
  • Normal sync with buffer alive continues to work as before

When a buffer is killed while an async HTTP request is in flight,
markers pointing into that buffer become stale: `marker-buffer'
returns nil.  Every `with-current-buffer (marker-buffer marker)'
and `org-with-point-at marker' call in a deferred callback then
signals an error because `set-buffer' receives nil.

Add nil checks on `marker-buffer' before using markers in:

- `org-gcal--with-point-at-no-widen' (macro)
- `org-gcal--sync-update-entries'
- `org-gcal--post-event' (HTTP 412 and success callbacks)
- `org-gcal--delete-event' (HTTP 412 callback)
- `org-gcal-delete-at-point' (:finally callback)

Each guard signals a descriptive error that the existing
`deferred:error' handlers can catch and log, rather than letting
Emacs error out with a confusing "Wrong type argument: bufferp, nil".
@benthamite benthamite force-pushed the fix/guard-stale-markers branch from 9696a3f to fcc8cdf Compare March 21, 2026 10:46
@telotortium telotortium self-requested a review April 27, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants