EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Memory leak while using sendMessageCallback

Also by EldoS: SecureBlackbox
200+ components and classes for digital security, signing, encryption and secure networking.
#21243
Posted: 08/29/2012 18:31:14
by Sudhanshu  (Basic support level)
Joined: 08/29/2012
Posts: 6

Hi,

I am new to MsgConnect and using it for p2p communication in a cluster for my research project. I am using sendMessageCallback function to request an object OBJ from Node A to B. It works as following:

Node A sends request RQ to Node B regarding OBJ using sendMessageCallback. Node B gets an event E with message M and gets the OBJ from its local cache. It updates the received message M with OBJ and sets M as handled. Node A on receiving callback extracts the OBJ out of message M.

My issue is when Node B while handling event tries to send the updated message back it required to create a memory buffer BUF on heap and copy all serialized data into it, so that memory pointed by "MCMessage.Data" is persisted till message is actually sendback. But once message is actually sent back I should delete this buffer, else it will simply leak. Unfortunately I am unable to find any function which can tell me that it is safe now to delete the BUF. Can you suggest some way to deal with this situation?

I am not using any Garbage Collector library for this C++ (linux) research project.

I know this buffer should persist only per dispatch message call, at end of dispatch message call the message will be send and I can reuse same buffer. But I am unable to pass some buffer handle to it, which can be used in Message event handler.

Also suggest if I can use a some other function which supports such messaging?

I am adding my MSCtest_cpp.txt file with this message for your reference. I am creating a buffer in line 61.

-Thanks


[ Download ]
#21248
Posted: 08/30/2012 01:32:47
by Eugene Mayevski (EldoS Corp.)

Your problem is in event2() function:

if you receive the data (in Message.Data) and you change the pointer contained in Message.Data, then before changing the pointer you need to free previous memory block (or copy the pointer and free it later) using MCMemFree() function.

Now when you put new pointer to Message.Data, MsgConnect will free this pointer itself later, so you don't need to care about it.

If you take another look at samples, they show how this is done.


Sincerely yours
Eugene Mayevski
#21283
Posted: 08/30/2012 15:36:20
by Sudhanshu  (Basic support level)
Joined: 08/29/2012
Posts: 6

Thanks Eugene, that helps.

Can you help me locate samples. I tried to find it in source code, but I saw only MCtest.cpp in Demos. Is it available on some web location?
#21288
Posted: 08/31/2012 00:38:22
by Eugene Mayevski (EldoS Corp.)

Indeed for Linux there's only MCTest available. All other samples are only present for Win32 in full version (which is packed only for Windows).


Sincerely yours
Eugene Mayevski
#21343
Posted: 09/06/2012 19:29:00
by Sudhanshu  (Basic support level)
Joined: 08/29/2012
Posts: 6

Hi Eugene,

I have one more question regarding MsgConnect. Is DispatchMessage() call thread-safe? I plan to create a thread pool for handling the events and callback for every messenger.

-Thanks
#21344
Posted: 09/07/2012 01:27:35
by Eugene Mayevski (EldoS Corp.)

Yes, all methods are thread-safe.


Sincerely yours
Eugene Mayevski
#21545
Posted: 09/14/2012 16:54:51
by Sudhanshu  (Basic support level)
Joined: 08/29/2012
Posts: 6

Hi Eugene,

I am able to run my p2p MsgConnect based messaging code on my local machine (ubuntu 12.04), but if I run it on a 48 core server machine in my lab ubuntu 10.04, I see MsgConnect library to stuck on select call in:

file : MCSocket.cpp
function : MCSocketTransportJob::PerformHandshake()
line : 380: select_res = select((mcInt32)highSocketHandle + 1, &FDRecvSet, NULL, NULL, PTV);

while trying to send first message to remote host. I tried to enable InactivityTime (1000 ms) and increasing AttemptsToConnect (50). Still it was able to send message 2-3 times out of 50 attempts, all other select call timed out.

At same select call place, there is a commented ifdef condition regarding the __GNUC__, when I enable this ifdef condition or use GNUC definition select, It don't get stuck and all messages get passed properly.

My question is: what was the purpose of this GNUC condition? and why it got commented? Is it ok if I enable ifdef condition or it is just by luck messaging is happening properly and some problem still lies there?

I am attaching MCSocket.cpp here for your reference.

My whole project is open source and available here:
http://code.google.com/p/ssrg-hyflow-cpp/

I am using MsgConnect under src/util/networking/msgConnect/.


[ Download ]
#21546
Posted: 09/15/2012 01:39:17
by Eugene Mayevski (EldoS Corp.)

Now as I have re-read documentation and have written (and deleted) the answer to your question, I see that we misunderstood documentation and passed wrong value to select() in code. You need to pass the number of descriptors in the set there (depending on particular place in code this would be either 1 or 2 descriptors).

In Windows first parameter is ignored, and on some Unix system incorrect value works (as the socket handle is always larger than two), that's why we never came across the problem.

You would need to make changes all over the code in your version: version 1 won't be updated by us as we have moved to MsgConnect 2 code base (which is not yet ready for public).


Sincerely yours
Eugene Mayevski
#21547
Posted: 09/16/2012 15:17:20
by Sudhanshu  (Basic support level)
Joined: 08/29/2012
Posts: 6

Thanks Eugene, I will update as required. Regarding MsgConnect 2 any idea by when it will be ready?

*Edited:

Additionally, I have found that after running the MsgConnect around 50+, I get the MsgConnect::EMCError in MCSyncs.cpp:line 59 originating from semget() call line 48, and to make it work again I have to reboot the system. I tried the "ipcrm -s 0" to remove the created semaphore by MsgConnect, but it did not help. Is there a way to recover system without rebooting?

Got answer for it: In msgConnect semaphore is clean up properly. Need to use ipcs to first find all the semaphore ids and then clean it. Actually in linux generally allowed to create 128 semaphores, therefore after creating 128 MCMessengers it will start throwing error.
#21551
Posted: 09/17/2012 01:15:09
by Eugene Mayevski (EldoS Corp.)

Version 2 will be released in a couple of months, not earlier.

Quote
Sudhanshu wrote:
after running the MsgConnect around 50+,


About 50+ of what?

Quote
Sudhanshu wrote:
In msgConnect semaphore is clean up properly


Is it cleaned up or is it NOT cleaned up? Also, what is "properly" in this case?


Sincerely yours
Eugene Mayevski
Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.

Reply

Statistics

Topic viewed 11369 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!