10-24-2018, 05:04 PM
Hi,
I have an extremely simple SmtpServer set up to simply receive emails and write them to disk. My problem is that over several hours the number of active threads just keeps growing, leading me to believe they are not being freed correctly. I further have to conclude it is quite likely as a result of something I am doing or not doing that is causing this, however for the life of me I cant seem to identify the problem.
I have attached my sources, they do contain an external reference to a text file logging routine that is thread safe (file protected by critical section) that has been used without issue for many years.
In my current setup I am binding to 20 IP addresses and they all seem to receive and handle the incomming email as expected. The load on the system is between 1 and 5 messages per minute. after 24 hours there are well over 1,000 threads active, this would not be all the threads created (fewer than messages received) in that period.
By my speculation my error should be in my configuration of the component
with WwolSmtpServ do
begin
ReuseSocket := rsTrue;
AllowPipelining := True;
ServerName := 'WWOL SMTP server';
DefaultPort := 25;
ListenQueue := 50;
MaxConnections := 0;
MaxMsgSize := 0;
TerminateWaitTime := 500;
UseNagle := True;
UseTLS := utNoTLSSupport;
end;
OR in my component exception handlers
procedure TdSmtpServ.WwolSmtpServException(AContext: TIdContext; AException: Exception);
begin
try
if ((AException is EIdConnClosedGracefully) or (AException is EIdNotConnected)) then
begin
Exit;
end
else
begin
if AContext.Connection.Connected then
begin
Log(Now, 0, 1, AContext.Binding.IP, AContext.Binding.PeerIP, AException.ClassName, AException.message + ' - ' + ' SmtpServException still connected');
AContext.Connection.Disconnect;
end
else
Log(Now, 0, 1, AContext.Binding.IP, AContext.Binding.PeerIP, AException.ClassName, AException.message + ' - ' + ' SmtpServException disconnected');
// AContext.Connection.Disconnect(False);
end;
except
on E: Exception do
begin
dmMain.TextLog('WwolSmtpServException : ' + E.Message);
dmMain.TextLog('WwolSmtpServException : ' + AContext.Binding.IP + ' : ' + AContext.Binding.PeerIP + ' : ' + AException.ClassName + ' : ' + AException.message);
end;
end;
end;
procedure TdSmtpServ.WwolSmtpServListenException(AThread: TIdListenerThread; AException: Exception);
begin
// Log(logModerate, 0, 'TdSmtpServ', 'WwolSmtpServListenException', '', '', AException.Message);
Log(Now, 0, -3, AThread.Binding.IP, AThread.Binding.PeerIP, AException.ClassName, AException.message + ' - WwolSmtpServListenException');
// AThread.Connection.Disconnect;
end;
OR in the component disconnect event
procedure TdSmtpServ.WwolSmtpServConnect(AContext: TIdContext);
begin
Log(Now, 0, -4, AContext.Binding.IP, AContext.Binding.PeerIP, 'WwolSmtpServConnect',
AContext.Binding.DisplayName + ' - ' + ' WwolSmtpServConnect');
end;
I am hoping I have missed something stupid and some fresh eyes might see the obvious,
Thanks for any assistance
-Allen
I have an extremely simple SmtpServer set up to simply receive emails and write them to disk. My problem is that over several hours the number of active threads just keeps growing, leading me to believe they are not being freed correctly. I further have to conclude it is quite likely as a result of something I am doing or not doing that is causing this, however for the life of me I cant seem to identify the problem.
I have attached my sources, they do contain an external reference to a text file logging routine that is thread safe (file protected by critical section) that has been used without issue for many years.
In my current setup I am binding to 20 IP addresses and they all seem to receive and handle the incomming email as expected. The load on the system is between 1 and 5 messages per minute. after 24 hours there are well over 1,000 threads active, this would not be all the threads created (fewer than messages received) in that period.
By my speculation my error should be in my configuration of the component
with WwolSmtpServ do
begin
ReuseSocket := rsTrue;
AllowPipelining := True;
ServerName := 'WWOL SMTP server';
DefaultPort := 25;
ListenQueue := 50;
MaxConnections := 0;
MaxMsgSize := 0;
TerminateWaitTime := 500;
UseNagle := True;
UseTLS := utNoTLSSupport;
end;
OR in my component exception handlers
procedure TdSmtpServ.WwolSmtpServException(AContext: TIdContext; AException: Exception);
begin
try
if ((AException is EIdConnClosedGracefully) or (AException is EIdNotConnected)) then
begin
Exit;
end
else
begin
if AContext.Connection.Connected then
begin
Log(Now, 0, 1, AContext.Binding.IP, AContext.Binding.PeerIP, AException.ClassName, AException.message + ' - ' + ' SmtpServException still connected');
AContext.Connection.Disconnect;
end
else
Log(Now, 0, 1, AContext.Binding.IP, AContext.Binding.PeerIP, AException.ClassName, AException.message + ' - ' + ' SmtpServException disconnected');
// AContext.Connection.Disconnect(False);
end;
except
on E: Exception do
begin
dmMain.TextLog('WwolSmtpServException : ' + E.Message);
dmMain.TextLog('WwolSmtpServException : ' + AContext.Binding.IP + ' : ' + AContext.Binding.PeerIP + ' : ' + AException.ClassName + ' : ' + AException.message);
end;
end;
end;
procedure TdSmtpServ.WwolSmtpServListenException(AThread: TIdListenerThread; AException: Exception);
begin
// Log(logModerate, 0, 'TdSmtpServ', 'WwolSmtpServListenException', '', '', AException.Message);
Log(Now, 0, -3, AThread.Binding.IP, AThread.Binding.PeerIP, AException.ClassName, AException.message + ' - WwolSmtpServListenException');
// AThread.Connection.Disconnect;
end;
OR in the component disconnect event
procedure TdSmtpServ.WwolSmtpServConnect(AContext: TIdContext);
begin
Log(Now, 0, -4, AContext.Binding.IP, AContext.Binding.PeerIP, 'WwolSmtpServConnect',
AContext.Binding.DisplayName + ' - ' + ' WwolSmtpServConnect');
end;
I am hoping I have missed something stupid and some fresh eyes might see the obvious,
Thanks for any assistance
-Allen