superflexible 1 Posted yesterday at 12:26 AM Hello, I am using TSslFtpClient in a multithreaded application. I get crashes inside the OpenSSL DLLs while uploading or downloading many smaller files in three separate threads (so three at a time). I set the Multithreaded property to true. I create all components in code, not in a DFM. So my question is, should I call TSslFtpClient.Create(nil) in the application's main thread, or in the thread where I am actually using it? Currently I have a method CreateComponents which I call via TThread.Synchronize(nil,CreateComponents). Are there any other precautions I have to take? I read about all the async recommendations but I cannot redesign the application from scratch. Many thanks. Share this post Link to post
Angus Robertson 617 Posted yesterday at 09:53 AM Using threads to handle multiple components in parallel is unnecessary, provided you are using async methods, so fully event driven. I've done tests with hundreds of components running in parallel, the SSL negotiation takes a while so eventually limits the number in parallel. The FTP component should usually be created and destroyed within the thread. There is a specific component for your purpose, TIcsFtpMultiThread in OverbyteIcsFtpMult.pas with a sample OverbyteIcsXferTst. Angus Share this post Link to post
superflexible 1 Posted yesterday at 10:23 AM (edited) Hi, many thanks for your reply! My application already creates the threads, there is no way around it. I cannot use a component that creates its own threads. The threads are already there. I will look into it further and check if the latest ICS update maybe fixes the crashes. Edited yesterday at 10:23 AM by superflexible Share this post Link to post
Olli73 6 Posted yesterday at 10:32 AM At least createCompomponents should not be synchronized so that components gets created in thread context. Share this post Link to post
superflexible 1 Posted yesterday at 11:03 AM Many thanks! I'll try it. And I'll look at the source code of TIcsFtpMultiThread to learn how it does the threading. Share this post Link to post
Angus Robertson 617 Posted yesterday at 12:25 PM On the general issue of using threads, remember that the ICS web and FTP servers support hundreds of simultaneous clients without using threads, I've never understood why so many people assume that threads are necessary to do two or more client connections at once. Unless they are migrating from using blocking components... when the code should be rewritten properly. At some point, there will be a new ICS threaded server component, since threads are necessary to use more than one CPU, but the server will generally only need one thread per CPU, with multiple clients in each thread. Angus Share this post Link to post
PeaShooter_OMO 24 Posted 9 hours ago 20 hours ago, superflexible said: I cannot use a component that creates its own threads Why? Would you mind elaborating on this? Share this post Link to post
Angus Robertson 617 Posted 6 hours ago Windows itself uses a thread for each async socket. Angus Share this post Link to post
superflexible 1 Posted 4 hours ago Hi, I think I chose the thread subject wrong. My real question is if there are/were any issues with crashes in OpenSSL and how I can prevent them. I don't want to discuss the pros and cons of threads. Share this post Link to post
Angus Robertson 617 Posted 3 hours ago No, OpenSSL is widely used with threaded programs, provided those programs are written correctly. Angus 1 Share this post Link to post
FPiette 390 Posted 3 hours ago 22 minutes ago, superflexible said: My real question is if there are/were any issues with crashes in OpenSSL and how I can prevent them. Open a new discussion with a correct the question. And add as many details as possible from your code. Without details, we cannot help much. I also suggest you create a minimal reproducible sample program which demonstrate the bad behavior you see in your actual code. Share this post Link to post