[fpc-pascal] teventobject.create fails with error 161

Snorkl e tony.caduto at gmail.com
Fri Oct 14 02:43:38 CEST 2016

Hi, Just wondering if anyone has any ideas.
I am using FPC 3.0 by the way.

Anyway, I am using a third party SFTP server lib and it creates a thread
inherited from tthread and in the create event of the tthread descendant it
does this:
(It uses this thread to read and write data on the socket)

FDataAvailable := TEvent.Create(nil, True, False, '');  //tevent maps to

  if (lasterr <> 0)   then
         SetLastError(NO_ERROR);  //<--I added this an attempt to recover
from the error
         raise Exception.Create(SCannotCreateEvent+':'+msg);

after the call to FDataAvailable it always has a handle pointer, but what
seems very random like GetLastError will return non 0 always with code 161
which is invalid path name.
When this occurs all new connections will fail, the process becomes useless
and I have stop it.

If I remove the call to getlasterror and ignore it, the threads go into
100% cpu usage in the while loops used to read or write when the error does

Users can actually connect but not transfer any data.

Also when I compile as 64bit the odds of this happening go way down and I
can sometimes transfer 10000 files before it happens, on 32bit it happens
much more frequently.

Apparently this is only a issue on Windows hence the compiler defs for

I did report this issue to the vendor and they said they are looking into
it but that could take months.

Anyone have any ideas one why teventobject.create is failing? Even though
it does have a hander pointer is it possible it's somehow a bad pointer?

This happens on windows 7 through 10 and even on PCs with lots of
resources(32gb ram, SSD hard drive and no corporate bloatware.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20161013/d3d937ed/attachment.html>

More information about the fpc-pascal mailing list