linux : Error: Failed to add descriptor xx to epoll descriptor xx

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 667
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

linux : Error: Failed to add descriptor xx to epoll descriptor xx

Postby briceandre » Sun Jul 23, 2017 2:07 pm

Dear all,

I have a program written with wxWidgets 3.0.2. It is aimed at running on a raspberry (raspbian, gcc compiler, only wxWidgets CORE services, as no GUI is running on the raspberry). But I test it on Windows (mscv 2012 compiler, wxWidgets compiled with GUI services).

This program widely uses wxDatagramSocket. Under Windows, the program executes fine and without any warnings.

But when running under linux, even if the behaviour of the program looks fine, I am completely spammed with warnings of the type :
13:55:03: Error: Failed to add descriptor 6 to epoll descriptor 5 (error 17: File exists)

This error seems to occur each time I perform a

Code: Select all

WaitForRead(-1);
on the socket.

The socket is initialised as below:

Code: Select all

   wxIPV4address data_reception_address;
   data_reception_address.AnyAddress();
   data_reception_address.Service(LOCAL_DATA_PORT);

   wxDatagramSocket* data_receiving_socket;
   data_receiving_socket = new wxDatagramSocket(data_reception_address, wxSOCKET_NOWAIT|wxSOCKET_REUSEADDR);


A dedicated wxThread is in charge of data reception. The code that performs reception looks like this:

Code: Select all

         while (!shall_exit)
         {
            /* Wait for something to read */
            data_receiving_socket->WaitForRead(-1);

            /* Read whole buffer */
            int32 reception_size = data_receiving_socket->RecvFrom(eib_net_ip.data_reception_address, eib_net_ip.data_reception_buffer, DATA_RECEPTION_BUFFER_SIZE).LastReadCount();
           
            ....
          }


My original code used same wxSocket to send data in a thread and, in parallel, receive data in another thread. But due to this warning, I splitted the code and use two different wxSockets. So, there is no more any concurrent access to the socket.

Any help would be very appreciated.

Regards,

Brice

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 667
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Re: linux : Error: Failed to add descriptor xx to epoll descriptor xx

Postby briceandre » Thu Dec 07, 2017 6:48 am

I did some investigations about this problem, and found other problems when using wxSocket in secondary thread under a nnon-gui linux application.

The problem described above (epoll descriptor warning) seems to occur only if using a wxDatagramSocket in a secondary thread. But for both wxDatagramSocket and wxClientSocket, there is another problem: after some times, the event loop running on the main thread is messed and starts using 100% of CPU (a kind of busy wait). Application is still working properly, but with a CPU usage of 100% on CPU core on which main thread is running.

I did several tests with different wxSocket parameters hoping that wxWidgets would understand that I don't want to use events with the sockets managed in secondary threads, but with no success.

I finally solved my problem by changing my implementation and using native linux sockets in secondary threads (my application is still using wxWidgets sockets, but only in main thread, which does not cause any trouble).

I tested with wxWidgets 3.0.2 and with last unstable 3.1.0 versions, both with same results.

If someone has a clue on what is going wrong, I am interested to know. But I really think that my problem is linked to a bug in wxWidgets when using sockets in a secondary thread in an application compiled without gui support (problem that probably messes event management). So, for now, I will give-up and stop using wxSockets.

Regards,
Brice

PS : just a small precision: the exact same application runs properly under windows, but I only tested with a gui-enabled wxWidgets library on this platform.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2052
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: linux : Error: Failed to add descriptor xx to epoll descriptor xx

Postby ONEEYEMAN » Thu Dec 07, 2017 4:47 pm

Hi,
Can you reproduce the problem with the minimal changes to the console/thread/socket sample?
Preferably on 3.1 or even Git HEAD.

Thank you.

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 667
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Re: linux : Error: Failed to add descriptor xx to epoll descriptor xx

Postby briceandre » Fri Dec 08, 2017 4:36 am

With minimum changes : certainly not...

All samples widely use gui functions. My problem only occurred on a platform that has no X11 server (and thus, I cannot compile with a gui-enabled wxWidgets version).

Moreover, socket sample uses sockets with events. As my bug occurs when using sockets in secondary threads, I cannot use events to manage those sockets.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2052
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: linux : Error: Failed to add descriptor xx to epoll descriptor xx

Postby ONEEYEMAN » Fri Dec 08, 2017 3:50 pm

Hi,
What about console sample?
Moreover, if you use threads - how do you communicate to the main (GUI) thread? You have to have an events for that. It is the only recommended way for that.

Thank you.

User avatar
eranon
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 652
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: linux : Error: Failed to add descriptor xx to epoll descriptor xx

Postby eranon » Fri Dec 08, 2017 8:12 pm

Beside the fact chance your worker thread will have to communicate data to the main thread sooner or later, I see a wxUSE_EPOLL_DISPATCHER in https://github.com/wxWidgets/wxWidgets/ ... atcher.cpp. So, what if you disable it?
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 667
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Re: linux : Error: Failed to add descriptor xx to epoll descriptor xx

Postby briceandre » Sat Dec 09, 2017 7:35 am

ONEEYEMAN

Yes, I use events to communicate between worker thread and main thread : the worker thread is filling a common memory (protected with mutex) and, when ready, posts an event so that the main thread is consuming produced data. There is no communication in the other direction.

Bu I am not sure I get your point: I don't think there is a bug in this part, and when replacing wxSocket by linux native socket, this mechanism works properly without any problem.

My guess about the events is that, even if I do not use socket events, I think that Wait and Read operations on wxSockets from secondary thread is messing the event management stuff of wxWidgets.

Using the event mechanism that allows communication between both threads does not seem to cause any issue (new version of program is now running from a little more than 48h, and still no issue in main thread event loop)

eranon

I cannot disable epoll dispatcher without replacing it by something else. This mechanism is used by main thread event loop to perform a blocking wait on a new event to process. My problem is that, at a point, this mechanism stops working and starts a kind of busy-wait, resulting in a CPU load of 100%. If I deactivate epoll at compilation time, what do I put in place instead ?

User avatar
doublemax
Moderator
Moderator
Posts: 11528
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: linux : Error: Failed to add descriptor xx to epoll descriptor xx

Postby doublemax » Sat Dec 09, 2017 8:33 am

I've never used wx sockets, but i have a feeling you're using them incorrectly. Did you read the chapter about sockets in the wxWidgets book? The book is a little outdated, but i think that chapter is very good.

I would also suggest to explain the problem again on the mailing list.
https://groups.google.com/forum/#!forum/wx-users
Use the source, Luke!

User avatar
eranon
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 652
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: linux : Error: Failed to add descriptor xx to epoll descriptor xx

Postby eranon » Sat Dec 09, 2017 2:18 pm

briceandre wrote:I cannot disable epoll dispatcher without replacing it by something else. This mechanism is used by main thread event loop to perform a blocking wait on a new event to process. My problem is that, at a point, this mechanism stops working and starts a kind of busy-wait, resulting in a CPU load of 100%. If I deactivate epoll at compilation time, what do I put in place instead ?

I never used wxSockets directly (infirectly, yes, since classes like wxHTTP, wxURL, wxFTP should use it). I don't know what happens when it's disabled (don't know the internal), but if there is a preprocessor definition, it's because it can be enabled or disabled (the epoll mechanism is not the only one talking about sockets and maybe not necessary in your case: https://stackoverflow.com/questions/829 ... nd-threads)... Otherwise, what's the justification of its existence?

Just in case: did you call wxSocketBase::Initialize() in your main thread before the creation of your worker one?

--
EDIT: Just seen (http://docs.wxwidgets.org/3.0/page_wxusedef.html) it exists a wxUSE_SELECT_DISPATCHER definition. So, maybe (with caution since I didn't digg) you have the choice between wxUSE_EPOLL_DISPATCHER or wxUSE_SELECT_DISPATCHER.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]


Return to “Platform Related Issues”

Who is online

Users browsing this forum: No registered users and 1 guest