404 when downloading an artefact over https when path has a '+' in it

TeamCity Enterprise 10.0.5 (build 42677) running on Windows Server 2012

I have experienced a problem in TeamCity where my build kept failing on all of our agents. It was unable to download one of the artifacts from a dependency. When looking in the build log I see this error (I have removed some sensitive information from the paths):

Failed to resolve artifact dependency < :: Build, build #1.2.179 [id 158323]>: Failed to resolve packages/Microsoft.AspNet.WebApi.Client.5.2.3/lib/portable-wp8+netcore45+net45+wp81+wpa81/System.Net.Http.Formatting.dll: Failed to download [https://<our domain>/httpAuth/repository/download/<my build configuration>_Build/158323.tcbuildid/packages/Microsoft.AspNet.WebApi.Client.5.2.3/lib/portable-wp8%2Bnetcore45%2Bnet45%2Bwp81%2Bwpa81/System.Net.Http.Formatting.dll]: Illegal status [404] while downloading https://<out domain>/httpAuth/repository/download/<my build configuration>_Build/158323.tcbuildid/packages/Microsoft.AspNet.WebApi.Client.5.2.3/lib/portable-wp8%2Bnetcore45%2Bnet45%2Bwp81%2Bwpa81/System.Net.Http.Formatting.dll: Not Found (jetbrains.buildServer.artifacts.impl.SourcePathAwareResolvingFailedException)

I tried downloading the artifact using the TeamCity UI and I receive the following:

HTTP Status 404 - Artifact does not exist: 'packages/Microsoft.AspNet.WebApi.Client.5.2.3/lib/portable-wp8 netcore45 net45 wp81 wpa81/System.Net.Http.Formatting.dll' in build #1.2.179

The problem only appears on this particular file in the artifact tree and I have come to the conclusion that it is because it contains a '+' in its path. All other files that do not contain a '+' in the path work fine. 

After a bit of trial and error, I managed to discover that the problem only occurs if I am connecting to the TeamCity UI over SSL. When trying the exact same thing over a non-SSL connection it works. I then modified one of our build agents to set the serverURL in the buildAgent.properties file to be non-SSL and the build started working on that agent.  

Is this a bug or is there a setting I can change to make it work when connecting over SSL?

0
4 comments

Hi David,

Do you connect to SSL via a proxy? This usually happens when the proxy (usually IIS) isn't properly configured to pass the parameters of the request. This can usually be accomplished by tweaking a bit the parameters of the proxy configuration. You can usually check whether this is the case by temporarily disabling the proxy or accessing the artifacts' url without using the proxy, which is exactly what you described. Can you check that?

0
Avatar
Permanently deleted user

Hi Denis,

Thanks for your reply. Yes, we do use IIS as a reverse proxy. I have tried bypassing it and it works as you suggested. I will take a look at the re-write rules.

 

0
Avatar
Permanently deleted user

I have managed to resolve the problem. It took me a lot longer that it should so I thought I would share what I did to resolve it.

The main issue I faced was with double encoding of URLs. TeamCity outputs an encoded URL for me to click in the UI, however, the existing IIS rewrite rule was then encoding this again resulting in the TeamCity Apache server not being unable to resolve the artefact.

To fix the problem, ensure you have version 2.1 or higher of the IIS rewrite module installed. Turn useOriginalURLEncoding to false (see https://serverfault.com/a/882301 for instructions). If you do not set the usrOriginalURLEncoding option then you have an older version of the rewrite module.

Modify your rewrite rule to the following:

<rule name="TeamCityReverseProxy" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{UNENCODED_URL}" pattern="/(.*)" />
  </conditions>
  <action type="Rewrite" url="http://localhost:8080/{C:1}" />
</rule>

Setting useOriginalURLEncoding to false was the key to fixing the issue. It is defaulted to true which was causing the double encoding. You can read more about it in the Preserve original URL encoding section in this blog: https://blogs.iis.net/iisteam/url-rewrite-v2-1

 

 

0
Avatar
Permanently deleted user

Having been running this fix for a while now, we identified another problem where we were unable to delete parameters due to this rewrite rule. We kept getting an error message saying 'Unknown action removeParameter,removeParameter'. To fix the problem we had to modify the rewrite rules to be the following:

<rules useOriginalURLEncoding="false">
  <clear />
  <rule name="TeamCityDefaultReverseProxy" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
      <add input="{UNENCODED_URL}" pattern="(.*%2B.*)" negate="true" />
      <add input="{URL}" pattern="/(.*)" />
    </conditions>
    <action type="Rewrite" url="http://localhost:8080/{C:1}" logRewrittenUrl="false" />
  </rule>
  <rule name="Handle artifacts with + in path - TeamCity reverse proxy" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
      <add input="{UNENCODED_URL}" pattern="/(.*)" />
    </conditions>
    <action type="Rewrite" url="http://localhost:8080/{C:1}" />
  </rule>
</rules>

The first rule processes all of the requests, except for those that contain a '+' (%2B). They fall to the second rule which builds the rewrite rule using the unencoded url. 

 

0

Please sign in to leave a comment.