omegahat / RDCOMClient

GNU General Public License v2.0
77 stars 34 forks source link

Random "Failed to create COM object: Server execution failed" error with scheduled task #23

Open yb2125 opened 4 years ago

yb2125 commented 4 years ago

First, RDCOMClient is a great tool. Kudos to Mr. Lang and other contributors!

In my case, I have a Windows 10 scheduled task running an R script, in which RDCOMClient is used to access Outlook every 5 minutes. The scheduled task fails once in a while randomly with the "Failed to create COM object: Server execution failed" error recorded in the log file. Sometimes, it failed a few times and went back to working again. At other times, I had to restart my computer and the error went away after restart.

Another thing odd about this is that the code ran interactively without any problem in Rstudio when it failed with the scheduled task.

Any suggestion is greatly appreciated.

LELULAS commented 1 year ago

I have the same issue. Have tried so many different things to resolve it, including using a third-party task scheduler. If I manually run the task from the scheduler or from Rstudio or from the batch file it runs fine. If left to a task scheduler, it returns the same error message.

duncantl commented 1 year ago

Thanks for the information. I pushed a small change just now to the git repository (not the omegahat.net repository) that adds an extra error message which may provide more information. So you can use devtools(), etc. to install from the git repository and see if the error file (created by explicitly call writeErrors("the.file.name") gives any more information when this happens.

Unfortunately, client-server scenarios are hard to debug as the client doesn't get to see all the details of the server side. And it is possible for the operating system not to have the resources to create the server and just fail, or for the server itself to fail and we cannot readily tell the difference. Since it works regularly, I suspect the operating system may not have the resources at that time.

One thing to ensure is that you quit and remove any instances of DCOM servers that you create and no longer use. If you have a reference to them in R, the server will continue to exist even if you aren't using it. And that consumes resources and there may be a limit on how many server instances can be created. (And also, the operating system may just create one instance of that server and so there would be no problem. Hard to tell.)

lstarkey commented 1 year ago

Oh wow I wonder if my issue was not removing instances of DCOM servers...how would I check if this is the issue and then remove them?

Thank you so much for responding!