Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - mq_send() returns 0 but Trace Event Log shows Error: (10 Items)
   
mq_send() returns 0 but Trace Event Log shows Error  
Hello,

under certain circumstances, my system runs into a never ending message ping-pong between mqueue and another process. I 
was able to break this ping-pong and got a kernel event log.

It shows, that a Send Message from my process is answered with Error from mqueue (orange IPC arrow in timeline view).
The code of my process would handle a return value of -1 of mq_send(), but it seems to return 0.
I read the description of Communication event Error. It says, that the client (mqueue) calls MsgError() in that case. 
The description of MsgError() says, that it sets errno according to the given error parameter and returns MsgSend() with
 return value -1. Only if the given error parameter is 0, MsgSend() will return 0 (EOK).

So I assume, that MsgError() was called with error = 0 within mqueue. How can I now catch that error in my process?
Re: mq_send() returns 0 but Trace Event Log shows Error  
Which version of the POSIX Messge Queues are you useing: mqueue or mq? (pidin arg will tell you).
Which QNX version are you using?

One would need to have a look into the code to see how the implementation of mq_send() utilizes MsgSend(). I would 
expect that the return value of MsgSend() is directly passed back as a return value of mq_send() but I don't know 
because I don't have the code.

In any case, if a server process calls MsgError()  with status set to 0, then the return value of the original MsgSend()
 call will be -1 and errno set to 0. So after returning from mq_send() it is essential to check the return value of the 
function, not errno alone.

Regards,
Albrecht
Re: mq_send() returns 0 but Trace Event Log shows Error  
Hello,

I am using mqueue and QNX 6.6.0 2017/08/18-14:22:25EDT.

Regards,
Jan
Re: mq_send() returns 0 but Trace Event Log shows Error  
I found another point in the Trace Event Log:
Event, Time, Owner, Type, Data
2136099, 17s 424ms 445us, myProcess Thread 1, MsgSendv Enter, coid 0x6 msg0 0x100102 function write()
[...]
2136105, 17s 424ms 448us, mqueue Thread 1, MsgError Enter, rcvid 0x20014 err 0
2136106, 17s 424ms 449us, mqueue Thread 1, Error, tid 3 pid 1179681 process myProcess
2136108, 17s 424ms 449us, mqueue Thread 1, MsgError Exit, ret_val 0
[...]
2136112, 17s 424ms 450us, myProcess Thread 1, MsgSendv Exit, status 0 rmsg 0x0

This is the mentioned error reply. It says "err 0", which is no error and thus I see EOK on return.
Re: mq_send() returns 0 but Trace Event Log shows Error  
"MsgError Exit, ret_val 0 "

I think that just means that the function call MsgError() inside the mqueue server returned 0, meaning success, and the 
client woke up.

Maybe if you use WIDE events when logging, it will tell you the value that it placed into the "status" parameter of 
MsgError().

Regards,
Al
RE: mq_send() returns 0 but Trace Event Log shows Error  
This is just how the code is written. When the mqueue resource manager handles the close_ocb() callback it replies by 
calling MsgError(rcvid, EOK). I have no idea why it does that instead of calling MsgReply(rcvid, EOK, NULL, 0), but that
 is how the code has been since 2001 (according to the revision history).

--Elad
________________________________________
From: Albrecht Uhlmann [community-noreply@qnx.com]
Sent: February-13-19 8:10 AM
To: ostech-core_os
Subject: Re: mq_send() returns 0 but Trace Event Log shows Error

"MsgError Exit, ret_val 0 "

I think that just means that the function call MsgError() inside the mqueue server returned 0, meaning success, and the 
client woke up.

Maybe if you use WIDE events when logging, it will tell you the value that it placed into the "status" parameter of 
MsgError().

Regards,
Al



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post119508
To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com
Re: RE: mq_send() returns 0 but Trace Event Log shows Error  
So the interesting question is: Why is close_ocb being called?

Jan, is your program multi-threaded and some other thread is closing the mqueue? Or are processes being spawbed and 
filedescriptors dup() ed and then closed?

Under which conditions does this behaviour occur? Can you reproduce it? Can you describe the setup (e.g. configuration 
of the particular mqueue, how many sending clients, how many reading clients)?

Regards,
Al
Re: RE: mq_send() returns 0 but Trace Event Log shows Error  
My setup is as follows:
Two multi-threaded processes (e.g. A and B) communicate between each other via mqueue using one of their threads.
When process A is terminated from outside (I see the "Dead" entry of every single thread of process A incl.the thread 
responsible for mqueue access), the ping-pong between process B and mqueue starts and never stops until I kill both 
processes A and B via SIGKILL. I wrote a little supervision program, which checks the lock of the system and then kills 
both processes A and B.

Re: RE: mq_send() returns 0 but Trace Event Log shows Error  
Hello Jan,
I would try to investigate why process A does not terminate properly. Because the process hanging around as zombie might
 cause a series of io_close events to be generated.

Actually, if all threads of a process are reported as DEAD in pidin I cannot imagine a mechanism why the process should 
not be removed. MAybe there is a parent/child relationship between process A and some other program? Please tell us, how
 do you launch processes A and B?

Regards,
Albrecht
Re: RE: mq_send() returns 0 but Trace Event Log shows Error  
Hello,

I think, I know the cause of the orange arrow. I played around with little test apps and saw that this arrow always 
appears, when no receiver is waiting with mq_receive() on a sent message. This is actually no real error, but it would 
be nice to be informed when my communication partner is gone and thus my message is not delivered.