title: Project Reactor Schedulers elastic using old threadlocal value
body: <p>I am using spring webflux to call one service from another via Schedulers.elastic()</p>
  
  <pre><code>Mono&lt;Integer&gt; anaNotificationCountObservable = wrapWithRetryForFlux(wrapWithTimeoutForFlux(
                  notificationServiceMediatorFlux.getANANotificationCountForUser(userId).subscribeOn(reactor.core.scheduler.Schedulers.elastic())
          )).onErrorReturn(0);
  </code></pre>
  
  <p>In main thread i am setting one InhertitableThreadLocal variable and in the child thread I am trying to access it and it is working fine.</p>
  
  <p>This is my class for storing threadlocal</p>
  
  <pre><code>@Component
  public class RequestCorrelation {
  
      public static final String CORRELATION_ID = "correlation-id";
  
      private InheritableThreadLocal&lt;String&gt; id = new InheritableThreadLocal&lt;&gt;();
  
      public String getId() { 
         return id.get(); 
      }
  
      public void setId(final String correlationId) { 
         id.set(correlationId); 
      }
  
      public void removeCorrelationId() {
         id.remove();
      }
  }
  </code></pre>
  
  <p>Now the issue is first time its working fine meaning the value i am setting in threadlocal is passed to other services.</p>
  
  <p>But second time also, it is using old id(generated  in last request).</p>
  
  <p>I tried using Schedulers.newSingle() instead of elastic(), then its working fine.
  So think since elastic() is re-using threads, thats why it is not able to clear / or it is re-using.</p>
  
  <p>How should i resolve issue.
  I am setting thread local in my filter and clearing the same in myfiler</p>
  
  <pre><code>requestCorrelation.setId(UUID.randomUUID().toString());
  chain.doFilter(req,res)
  requestCorrelation.removeCorrelationId();
  </code></pre>