EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Getting Hang On Shutdown (VB.Net)

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
#2887
Posted: 05/08/2007 09:34:38
by Adam Leyshon (Standard support level)
Joined: 05/08/2007
Posts: 23

Hi, My name is Adam Leyshon. I have a question about MsgConnect, In VB.Net I am writing a simple application which just sends a message to the server every 15 seconds, this of course will be expanded upon later on, but it works. However when I call Socket.Shutdown(TRUE) in my Form.Disposing event the program just hangs on that line when I pause debugging, is there something else I need to do first?

EDIT: Sorry forgot to add: DLL Version is MsgConnect - version 1.5.7.55 - Released February 14, 2007
#2888
Posted: 05/08/2007 09:41:32
by Eugene Mayevski (EldoS Corp.)

Assuming that "Socket" means a socket transport and not a System.Net.Sockets.Socket, I can think of the following:

there's a lot of unsent or failed messages that stay in the queues. When you call shutdown, these messages are discarded and/or reported as failed (depending on the exact situation). This takes time.

Another possible reason is that the socket is not shut down properly. We had this issue some time ago (WinSock didn't correctly close UDP sockets, not closed by the application), but the problem has been solved. If you are not using the latest version (build 55), you need to update your version.


Sincerely yours
Eugene Mayevski
#2889
Posted: 05/08/2007 09:46:10
by Adam Leyshon (Standard support level)
Joined: 05/08/2007
Posts: 23

Yes, you are correct to assume that it is a TCP Socket, sorry I should have mentioned this earlier.

Here is the code for the sending part of the app.
Code
  Private Sub MsgOK(ByVal UserData As Object, ByRef Message As MsgConnect.MCMessage)
        Debug.Print("Message OK")
    End Sub
    Private Sub MsgFailed(ByVal UserData As Object, ByRef Message As MsgConnect.MCMessage)
        Messenger.CancelMessageEx(Message.MsgID, True)
    End Sub
    Private Sub MsgError(ByVal UserData As Object, ByRef Message As MsgConnect.MCMessage, ByVal ErrorCode As Integer)
        Messenger.CancelMessageEx(Message.MsgID, True)
    End Sub
    Private Sub SendMessage()
        SentLastMessage = New TimeSpan(System.DateTime.Now.Day, System.DateTime.Now.Hour, System.DateTime.Now.Minute, System.DateTime.Now.Second, System.DateTime.Now.Millisecond)
        Dim HBMsg As MsgConnect.MCMessage
        HBMsg = MsgConnect.MCMessenger.CreateMessageFromText(1, 2, 3, ComputerData, System.Text.Encoding.Default, False)
        Messenger.SendMessageTimeoutCallback("ToServer:192.168.0.4:14583|KeepAlive", HBMsg, 5000, New MsgConnect.MCNotifyProc(AddressOf MsgOK), New MsgConnect.MCNotifyProc(AddressOf MsgFailed), New MsgConnect.MCErrorProc(AddressOf MsgError), "", Creds)
        'If Messenger.GetMessageSent(HBMsg.MsgID) = False Then
Debug.Print(Socket.GetOutgoingMessagesCount.ToString)
    End Sub


As you can see I think I am correctly disposing of failed messages, although it is still hanging even when it has not sent any messages.

Thanks,
Adam Leyshon
#2890
Posted: 05/08/2007 10:35:07
by Eugene Mayevski (EldoS Corp.)

If it's hanging without sending any messages, then there's only one possible case that I mentioned - a problem with Winsock, for which we have added a workaround several builds ago. IF you are using build 55, please try to create a small sample that exposes the problem and post this sample here or to HelpDesk ( http://www.eldos.com/support/ticket_list.php )


Sincerely yours
Eugene Mayevski
#2900
Posted: 05/09/2007 04:56:30
by Adam Leyshon (Standard support level)
Joined: 05/08/2007
Posts: 23

Right well I added these lines to the code in Form_Closing Event, BTW: The TCPSocket is in stmServer mode.

Code
        Debug.Print(Socket.GetOutgoingConnectionCount.ToString)
        Debug.Print(Socket.GetOutgoingMessagesCount.ToString)
        Socket.Shutdown(True)


The Output was after sending one message:
Connections: 1
Messages Outgoing: 0

Then it Hangs. When i checked the connections i saw:
*.*.*.*:14583 (Blanked for Privacy ;)
127.0.0.1:3391 Outbound
127.0.0.1:3393 Inbound

What are these two other loopbacks for? those two only opened up when I invoked the Shutdown Method
#2901
Posted: 05/09/2007 05:00:11
by Adam Leyshon (Standard support level)
Joined: 05/08/2007
Posts: 23

I also tried making a new project with just: A TCPSocket, Queue and a Messenger.

Code
Public Class Form1

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        McSocketTransport1.Shutdown(True)
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        McSocketTransport1.Active = True
    End Sub
End Class


That opens and closes fine. So i don't think its a winsock problem.
#2904
Posted: 05/09/2007 05:17:23
by Eugene Mayevski (EldoS Corp.)

Quote
Adam Leyshon wrote:
What are these two other loopbacks for? those two only opened up when I invoked the Shutdown Method


UDP notification sockets. UDP is used to notify the transport thread which is select()'ing the transport socket, that the thread should perform an action.


I am not sure about what can cause the problem, so I welcome you to create a test case and submit it to HelpDesk ( http://www.eldos.com/support/ticket_list.php )


Sincerely yours
Eugene Mayevski
#2907
Posted: 05/09/2007 07:45:56
by Adam Leyshon (Standard support level)
Joined: 05/08/2007
Posts: 23

Im really sorry about this but it turns out it is my fault

When i put:
Code
Private Sub SocketTransport_OnDisconnected(ByVal Sender As Object, ByVal Args As MsgConnect.MCSocketDisconnectedEventArgs) Handles SocketTransport.OnDisconnected
        lblStatus.Text = "Disconnected..."
End Sub


It was causing a threading deadlock due to trying to set a label on which the form which was being closed with CheckForIllegalCrossThreads enabled.

I have now solved this, but can you tell me how im supposed to set text or do anything from these events?
#2909
Posted: 05/09/2007 09:55:03
by Eugene Mayevski (EldoS Corp.)

OnConnected and OnDisconnected events are fired in context of a worker (transport) thread. This is indeed mentioned in documentation. As for thread synchronization - it depends on the version of .NET. .NET 1.1 supported simplier inter-thread use of GUI objects. .NET 2.0 requires more strict approach.

We have the following code in one of SecureBlackbox samples:

Code
      private delegate void LogEventDelegate(String s);

      private void LogEvent(String s)
      {
         Object[] o = new Object[1];
         o[0] = s;
         this.Invoke(new LogEventDelegate(InnerLogEvent), o);
      }

      private void InnerLogEvent(String s)
      {
         if (editLogs.TextLength > 0)
            editLogs.AppendText("\r\n");
         editLogs.AppendText(s);
      }


Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.

Reply

Statistics

Topic viewed 5712 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!