TUniConnection: Only one usage of each socket address (protocol/network address/port) is normally permitted

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
miguelenguica
Posts: 18
Joined: Mon 11 Apr 2011 15:28

TUniConnection: Only one usage of each socket address (protocol/network address/port) is normally permitted

Post by miguelenguica » Thu 16 Feb 2017 17:05

I'm dynamically creating two TUniConnection inside a thread. Each of those 2 connections is made to a different database inside the same endpoint. I just have a single thread running at a time inside the app, but have 5 apps running simultaneously. The connections are made towards an AWS RDS Aurora (MySQL compatible) database. At the end of the thread I disconnect and free the 2 connections. The threads run continuously.

After 4 hours or so I'm getting this on the OnError event:

Code: Select all

THREAD thread_uniconnection1: Cannot connect to server on host 'XXX':
Only one usage of each socket address (protocol/network address/port) is normally permitted.
Socket Error Code: 10048($2740)
This is how I'm creating the TUniConnection objects:

Code: Select all

   thread_uniconnection1:= TUniConnection.Create(nil);
   thread_uniconnection1.Database:= XXX;
   thread_uniconnection1.LoginPrompt:= False;
   thread_uniconnection1.ProviderName:= 'MySQL';
   thread_uniconnection1.Server:= XXX;
   thread_uniconnection1.Username:= XXX;
   thread_uniconnection1.Password:= XXX;
   //events
   thread_uniconnection1.OnError:= UniConnectionErrorHistory;
   thread_uniconnection1.OnConnectionLost:= UniConnectionConnectionLostHistory;
   thread_uniconnection1.AfterDisconnect:= UniConnectionHistoryAfterDisconnect;
What am I doing wrong?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: TUniConnection: Only one usage of each socket address (protocol/network address/port) is normally permitted

Post by ViktorV » Fri 17 Feb 2017 07:41

Unfortunately, we could not reproduce the issue.
In order to get a detailed answer, please compose a small sample demonstrating the described behavior and send it using the contact form https://www.devart.com/company/contactform.html

miguelenguica
Posts: 18
Joined: Mon 11 Apr 2011 15:28

Re: TUniConnection: Only one usage of each socket address (protocol/network address/port) is normally permitted

Post by miguelenguica » Fri 17 Feb 2017 08:43

As I mentioned this happens when several instances of my app are working at the same time and only after 4 or so hours, using an Aurora RDS instance. I'll try to reproduce it in a simpler way and send it to you.

Meanwhile, please confirm if the way I'm creating the TUniConnection objects can be improved (maybe some options) and also the best way to discard them at the end of the thread. Also:

- Should I explicitly call TUniConnection.Disconnect at the end and then TUniConnection.Free or just TUniConnection.Free?
- Is it better that the thread has the FreeOnTerminate flag on?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: TUniConnection: Only one usage of each socket address (protocol/network address/port) is normally permitted

Post by ViktorV » Fri 17 Feb 2017 09:53

If you are using a multi-threaded application, then a separate connection per thread must be used.
You can only call the TUniConnection.Free method, as in this case the TUniConnection.Disconnect method is automatically called.

Post Reply