Weird behavior involving context switching, FBOs, and `glGetIntegerv` - driver bug?

I’ve managed to minimize a incredibly weird bug in one of my programs.

Basically:

  1. Create OpenGL contexts A and B
  2. Activate context B and bind GL_FRAMEBUFFER 0
  3. Activate context A and create a texture
  4. Activate context B and bind GL_FRAMEBUFFER 0
  5. glClearColor and glClear to red
  6. Create a target FBO X, set 0 as read FBO, X as draw FBO
  7. Activate context A and do nothing
  8. Activate context B and do nothing
  9. Call GLint out; glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &out);
  10. Blit framebuffers (from 0 to X)
  11. Assert that the result of the blit is red

The assertion will unexpectedly fail unless:

  • The glGetIntegerv call in step 9 is commented out;
  • OR the activation of context A in step 7 is commented out;
  • OR GL_FRAMEBUFFER is bound to 0 again between steps 8 and 9.

I have no idea why this is happening. I am on a RTX4090 with the latest driver, and I’ve also tried studio drivers and an older version from Oct 2024. Is this a driver bug, or am I doing something wrong?

Fully replicable example using SDL3: