[EHttpApiException] uROHttpAPI: Cannot create a file when that file already exists

Hi,

We’re having problems with our server application, both in our own test environments and on customer systems, whereby it suddenly goes unresponsive. When this happens no users can communicate with the server at all. When I check to see if the server is still listening on the relevant ports, sometimes it is and sometimes not.

The server application logs all exceptions encountered to the Windows event log and I’m seeing the above exception quite frequently so I’m suspecting that it has something to do with the problem.

What does this exception mean exactly? Can anyone shed any light on what the issue could be that’s giving rise to this exception? I’m reaching my wits’ end with this as it’s totally random and I can’t find any logic explanation for the issue.

ERROR_ALREADY_EXISTS error can be raised after calling HttpAddUrlToUrlGroup:
The specified URL conflicts with an existing registration.

or after calling HttpSetServiceConfiguration:
The specified record already exists, and must be deleted in order for its value to be re-set.

looks like, your application tries to [re]register already taken URL.

TROWinHttpServer tried to register http://+:8099/ by default.
This behavior can be changed with OnManualBind event like:

  ROWinHttpServer1.Server.AddUrl(...);

HttpAddUrlToUrlGroup is called always inside AddUrl.

HttpSetServiceConfiguration is called only when aRegisterURL parameter of AddUrl is set to True:

AddUrl(.., True);

Thanks but I’m still a bit confused. Why am I getting a slightly different error to the two you mentioned, as mine refers to a file already existing rather than a URL or record?

I’ll confess I’m not too au fait with HTTP stuff. My server listens on two ports for TCP and HTTP connections respectively. My client code uses TCP but the HTTP is used via SOAP from a web server application written by someone else.

All I’m doing with my TROWinHttpServer component is setting the port and then setting it active. I’m not attempting to re-register anything or even disabling or re-enabling it. It seems to work fine for 99.9% of the time, just every now and then I get this exception.

I’m not sure if the exception is related to the server issues I’m having as, when it happens, the server cannot be contacted via either TCP or HTTP but the fact the exception has been logged around the time the server goes unresponsive is too much of a coincidence I feel. This is the only small lead I have in tracking this down - as I said I’m running out of ideas as this problem is very infrequent and totally random so there’s no reliable way of tracking or reproducing it :frowning:

from Deciphering HTTP Server API Error Codes article:

ERROR_ALREADY_EXISTS (0xB7): You probably were trying to register an address that is already registered by another application.

Am I correctly understand, that your server usually works correctly and sometimes it stops working with ERROR_ALREADY_EXISTS error so it doesn’t generate this error immediately after starting? or it generates this error immediately after starting?

Yes that’s correct, it will work perfectly for weeks at a time and then suddenly it goes completely unresponsive and isn’t contactable by clients, either via TCP or HTTP and the service must be restarted. Quite often when this happens the above exception has been logged which is what’s leading me to believe it’s related.

Basically we have two server services, one is the main application server using RODA, the other is a web server service which communicates with the app server via SOAP for certain functions.

The amount of interaction between these services depends on how much use the individual customer makes of the web-based functionality. Interestingly, we’ve just deployed it to a customer who is making very heavy use of the web-server functionality and we’ve thus far had this issue arise twice in the last three days. This also seems to be pointing at the HTTP interface having something to do with the problems but I’m at a loss to explain exactly what or why.

I was wondering if I could put some additional logging in for the HTTP server, so I could log all access to the server via this interface, then perhaps I could see exactly what was being done at the time the issues arise, when they do. What would be the best thing to trap/log to achieve that?

Thanks.

Also, I’m using the TROWinHttpServer at present. I’m not entirely sure about the differences and relative merits of the different HTTP server channels but was wondering if it was worth switching to a different one to see how this fares?

Possibly the TROIpSuperHTTPServer as it uses Synapse and I’m already using the TROSynapseSuperTCPServer?

I think, you can put some additional logging in places where is this method is called:

procedure HttpCheck(HttpCallResult: ULONG);

so you can detect what exactly HTTP Server API function causes failure.
from Deciphering HTTP Server API Error Codes article:

ERROR_ALREADY_EXISTS (0xB7): You probably were trying to register an address that is already registered by another application.


each library (synapse/indy/WinHTTPAPI) has own advantages and disadvantages. so it has sense to try other one if you have some problems with specific library.

Of cource, you can use Synapse HTTP server - TROIpHTTPServer or TROIpSuperHTTPServer.
TROIpHTTPServer will consume less resources than TROIpSuperHTTPServer because it doesn’t have super http support.

Ok thanks for the help, I’ll try these options and see what happens.

I’ve managed to get hold of a log entry of this exception from one customer’s system where it seems to have occurred during initialisation when the service first starts and it activates the HTTP server:

An exception occurred: [EHttpApiException] uROHttpAPI: Cannot create a file when that file already exists

Stack trace:

(0000981D){ClarityServer.exe} [0040A81D] System.@RaiseExcept (Line 19696, “System.pas” + 51) + $0

(0097B70A){ClarityServer.exe} [00D7C70A] uROHttpApi.HttpCheck (Line 1046, “uROHttpApi.pas” + 2) + $2A

(0097FF01){ClarityServer.exe} [00D80F01] uROHttpApiServer.TROHttpApiServer.AddUrl (Line 536, “uROHttpApiServer.pas” + 4) + $22

(0097FFB1){ClarityServer.exe} [00D80FB1] uROHttpApiServer.TROHttpApiServer.BindUrls (Line 546, “uROHttpApiServer.pas” + 4) + $28

(0098028D){ClarityServer.exe} [00D8128D]
uROHttpApiServer.TROHttpApiServer.SetActive (Line 592,
“uROHttpApiServer.pas” + 21) + $3

(00981393){ClarityServer.exe} [00D82393]
uROWinHttpServer.TROWinHttpServer.IntSetActive (Line 298,
“uROWinHttpServer.pas” + 8) + $B

(004577B4){ClarityServer.exe} [008587B4] uROServer.TROServer.SetActive (Line 1284, “uROServer.pas” + 17) + $8

try to update AddUrl as

procedure TROHttpApiServer.AddUrl(aURL: string; aRegisterURL: boolean);
var
  ls: UnicodeString;
  flag: DWORD;
  err: DWORD;
begin
  ls := UnicodeString(aURL);
  if aRegisterURL then HTTP_RegisterURL(aUrl);
  if HttpAPI.Version.MajorVersion > 1 then begin
    err := HttpAPI.AddUrlToUrlGroup(fUrlGroupID,PWideChar(ls));
    if err = ERROR_ALREADY_EXISTS then begin
      // from https://msdn.microsoft.com/en-us/library/windows/desktop/aa364498%28v=vs.85%29.aspx 
      // flag can have values 0 or HTTP_URL_FLAG_REMOVE_ALL
      // I'm not sure what value should be used here so try both values
      flag := 0; 
      HttpCheck(HttpAPI.RemoveUrlFromUrlGroup(fUrlGroupID,PWideChar(ls),flag));
      err := HttpAPI.AddUrlToUrlGroup(fUrlGroupID,PWideChar(ls));
    end;
    HttpCheck(err);
  end
  else
    HttpCheck(HttpAPI.AddUrl(fReqQueueHandle,PWideChar(ls)));
end;

Ok I can give that a try.

Upon further investigation I may be going in slightly the wrong direction here. Looking at the few instances of this issue that we’ve had, it seems that this exception is only logged when the service is restarted. What happens is the server goes unresponsive so the service is restarted, then sometimes this exception is raised immediately after the restart and the server remains unresponsive.

From what I’m told by our support team, sometimes the service stop doesn’t actually terminate the process, which is still present in Task Manager and which they have to terminate manually. I’m guessing that whatever issue is causing the server to go unresponsive is responsible for this and that the server isn’t shutting down cleanly when the service is stopped. The subsequent restart then tries to re-register the URL for the HTTP server which fails because the old process is still running.

I’m guessing here as, like I said, I don’t know that much about the HTTP stuff and I’m also going on what I’m being told by the support team as I can’t reproduce the problem on demand. If this is the case then it does still look like something is going wrong on the HTTP side of things which is perhaps preventing a thread from terminating when the service is stopped. I guess I’m going to have to just add some more logging and then wait for another re-occurrence of the problem and hope this sheds some light on what causes the original problem.

Also, I’ve just tried using the Service Tester and it seems to be crashing on me all the time. Using either TCP or HTTP, if I point it at a service function which returns a simple integer (my server’s version number) it works fine. If I point it at another function in the same service which returns a struct then it crashes when I try to run it. Not sure what I’m doing wrong here.

Hello

I have update the AddURL with the above code, and it works for http://+:port/ .

But I would like to have the servive answer in http://+:{port}/{relative_uri} like http://+:8080/app1
But I get an “Invalid Path” .

Any Idea on how to support relative uris?

pls read Configuring HTTP and HTTPS article.

see also How to use SSL in Remobjects SDK?