If we have a web application that has a JAX-RS resource and another interface not related to JAX-RS (servlet or a JAX-WS web service, for example), but using resteasy client, we might have an issue where:
- If the JAX-RS endpoint is acessed and it is doing the providers registration;
- At the same time, the other endpoint that uses the client request API is accessed;
- The GZIPDecodingInterceptor will be registered twice
The consequence is that two GZIPDecodingInterceptor will try to parse the GZIP requests corrupting the gzipinputstream and leading to the following error everytime we try to use the client again:
The issue, as greatly found by our colleague Dennis, is that the client request will try to create a wrapped provider during the other providerfactory provider registration. which means that the following synchronized code block from RegisterBuiltin class won't protect us:
This issue is hidden by the ResteasyDeployment.start() is triggered in deployment phase. If we lazily start the ResteasyDeployment when the resource class is accessed. We can find the synchronized block actually is added to different object : ResteasyProviderFactory and ThreadLocalResteasyProviderFactory by resteasy client code in the same deployment.