Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4788

Reactor Context loss in BatchCursorFlux

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.8.0
    • Affects Version/s: None
    • Component/s: Reactive Streams
    • None

      Summary

      BatchCursorFlux uses a lambda to subscribe to batchCursorPublisher without propagating the subscriber context.

      How to Reproduce

      A tad difficult. 

       

      MongoClientSettings settings = MongoClientSettings.builder()
      		.contextProvider((ReactiveContextProvider) subscriber -> {
      			if (subscriber instanceof CoreSubscriber<?> cs) {
      
      				Map<Object, Object> map = cs.currentContext().stream()
      						.collect(Collectors.toConcurrentMap(Entry::getKey, Entry::getValue));
      				
      				// map is empty
      			}
      			
      			return …
      		}).build();
      
      // later:
      
      MongoCollection<Document> reproducer = operations.getCollection("foo").block();
      Flux.from(reproducer.find()).contextWrite(Context.of("key", "value")).blockLast();
      

       

      Additional Background

      Discovered during context propagation testing for observability. Other places where lambda-based subscribers are used might be affected, too.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            mpaluch@paluch.biz Mark Paluch
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: