# Docker + Xvfb + SDL-2.0.10: SDL\_PollEvent call bocks

**URL:** <https://discourse.libsdl.org/t/docker-xvfb-sdl-2-0-10-sdl-pollevent-call-bocks/33279>\
**Category:** SDL Development\
**Created:** [November 5, 2021, 10:45am UTC](https://discourse.libsdl.org/t/docker-xvfb-sdl-2-0-10-sdl-pollevent-call-bocks/33279 "2021-11-05T10:45:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhixiang](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/z/cdc98d/32.png) [@zhixiang](https://discourse.libsdl.org/u/zhixiang)\
**Post date:** [November 5, 2021, 10:45am UTC](https://discourse.libsdl.org/t/docker-xvfb-sdl-2-0-10-sdl-pollevent-call-bocks/33279/1 "2021-11-05T10:45:22Z")

</div>

I’m writing nodejs wrapped gui application running in Docker(Ubuntu Linux 20) with Xvfb:

`RUN apt-get update && apt-get install -y mesa-utils xvfb libglvnd-dev libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev mesa-utils-extra xorg-dev libx11-dev libgl1-mesa-glx`

`xvfb-run node test.js`

However, i find that SDL\_PollEvent may be in blocking wait status which cause nodejs main loop completely locked.

When i tracked source code of SDL-2.0.10, i found this:

```auto
/* Ack! X11_XPending() actually performs a blocking read if no events available */
static int
X11_Pending(Display * display)
{
...

```

Just who can tell me how to fix this or bypass it?

---

<div class="post-metadata">

**Author:** ![zhixiang](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/z/cdc98d/32.png) [@zhixiang](https://discourse.libsdl.org/u/zhixiang)\
**Post date:** [November 5, 2021, 10:49am UTC](https://discourse.libsdl.org/t/docker-xvfb-sdl-2-0-10-sdl-pollevent-call-bocks/33279/2 "2021-11-05T10:49:52Z")

</div>

> <https://github.com/kmamal/node-sdl/blob/master/src/javascript/events/index.js>

My way is a little simpler: i wrap a whole while(SDL\_PollEvent(&ev)){…} is a nodejs call, and use setInterval to periodically call it.

node-sdl wrappers a single SDL\_PollEvent call to a js function, and do while loop in js, but i doubt if it will run in blocking state in Xvfb virtual X server mode…

---

<div class="post-metadata">

**Author:** ![zhixiang](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/z/cdc98d/32.png) [@zhixiang](https://discourse.libsdl.org/u/zhixiang)\
**Post date:** [November 5, 2021, 10:55am UTC](https://discourse.libsdl.org/t/docker-xvfb-sdl-2-0-10-sdl-pollevent-call-bocks/33279/3 "2021-11-05T10:55:54Z")

</div>

From running log output, SDL\_PollEvent initially can receive SDL\_WINDOWEVENT events,

if i don’t do any event loop, then initial window ui will not come out(I use gstreamer to capture the window and use WebRTC streaming to get encoded picture out)

But later SDL\_PollEvent will not get any events, for there is no real input device in Xvfb-run mode?

---

<div class="post-metadata">

**Author:** ![zhixiang](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/z/cdc98d/32.png) [@zhixiang](https://discourse.libsdl.org/u/zhixiang)\
**Post date:** [November 5, 2021, 11:52am UTC](https://discourse.libsdl.org/t/docker-xvfb-sdl-2-0-10-sdl-pollevent-call-bocks/33279/4 "2021-11-05T11:52:44Z")

</div>

I try to use `SDL_PushEvent` to unblock the blocking-state SDL\_PollEvent:

```auto
    std::thread t([](){
        while(1){
            std::this_thread::sleep_for(std::chrono::seconds(1));
            SDL_Event evt;
            evt.type = SDL_KEYDOWN;
            evt.key.keysym.sym = SDLK_1;
            SDL_PushEvent(&evt);
        }
    });
    t.detach();

```

but not well working…

---

<div class="post-metadata">

**Author:** ![Daniel\_Gibson](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/daniel_gibson/32/3010_2.png) [@Daniel\_Gibson](https://discourse.libsdl.org/u/Daniel_Gibson)\
**Post date:** [November 5, 2021, 6:44pm UTC](https://discourse.libsdl.org/t/docker-xvfb-sdl-2-0-10-sdl-pollevent-call-bocks/33279/5 "2021-11-05T18:44:35Z")

</div>

`SDL_PollEvent()` really shouldn’t be blocking.

“Standard” event handling in normal SDL2 apps looks like:

```auto
SDL_Event ev;
while(SDL_PollEvent(&ev)) {
    switch(ev.type) {
      // handle event
    }
}
// and now render something
// ...

```

so if `SDL_PollEvent()` blocked, this wouldn’t work as the while-loop would never be left to render something.

AFAIK `SDL_PollEvent()` should be called in the main thread (i.e. the one that created the window), is that the case in your app?  
And what are you trying to do anyway? This mixture of node.js and SDL looks pretty wild, to be honest.

---

<div class="post-metadata">

**Author:** ![zhixiang](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/z/cdc98d/32.png) [@zhixiang](https://discourse.libsdl.org/u/zhixiang)\
**Post date:** [November 8, 2021, 2:35am UTC](https://discourse.libsdl.org/t/docker-xvfb-sdl-2-0-10-sdl-pollevent-call-bocks/33279/6 "2021-11-08T02:35:09Z")

</div>

I’m writing a service for receiving UI view render commands (in json format), and nodejs is used for WebSocket server and also for starting gstreamer to record the app window and push encoded video stream to a webrtc server/

---

<div class="post-metadata">

**Author:** ![cgutman](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/94ad74/32.png) [@cgutman](https://discourse.libsdl.org/u/cgutman)\
**Post date:** [November 10, 2021, 6:13pm UTC](https://discourse.libsdl.org/t/docker-xvfb-sdl-2-0-10-sdl-pollevent-call-bocks/33279/7 "2021-11-10T18:13:13Z")

</div>

Please try with the latest SDL code. That X11\_Pending() code was removed in [x11: Use XCheckIfEvent() instead of XNextEvent() for thread-safety · libsdl-org/SDL@9c95c24 · GitHub](https://github.com/libsdl-org/SDL/commit/9c95c2491cafb85de6ce09c653a5754f0d4cb2f3)
