title: Java Reactive hangs when calling repo operation inside map
body: <p>I'm new to this reactive world and having an issue when I want to map my user to another user.</p>
  <p>So the code is supposed to go to DB to find the user based on Username, then will need to create another user object and populate its Authority by calling another repository.</p>
  <p>Then I need the value so I used <strong>block</strong>.</p>
  <pre><code>Mono&lt;User&gt; userMono = userService.findByUsername(regularUser.getUsername())
              .map(u -&gt; {
                        User user = new User();
                        user.setUsername(u.getUsername());
                        user.setAuthority(userService.getAuthorities(u));
                        return user;
              });
  User usr = userMono.block();
  </code></pre>
  <p>I found that every time the code executes the block, it will stop working. the request to DB is never completed. I debugged and found that in <code>Mono#block</code> - <code>BlockingSingleSubscriber#blockingGet</code> the <code>getCount()</code> is 1, which will go to <code>await()</code>. This takes forever. I waited but the <code>getCount()</code> didn't reach 0 and there was no <code>InterruptedException</code> thrown.
  <a href="https://i.stack.imgur.com/hIlmK.png" rel="nofollow noreferrer">blockingGet</a></p>
  <pre><code>UserService.java
  
  @Autowired
  UserRepository userRepository;
  
  @Autowired
  AuthorityRepository authorityRepository;
  
  public Mono&lt;User&gt; findByUsername(String username) {
    return userRepository.findByUsername(username);
  }
  public Flux&lt;Authority&gt; getAuthorities(User user) {
    return authorityRepository.findAllByUserId(user.getId());
  }
  </code></pre>
  <p>I'm using Spring Boot 2.7.0<br />
  io.spring.dependency-management 1.0.11.RELEASE<br />
  spring-boot-starter-webflux<br />
  spring-boot-starter-data-mongodb-reactive</p>
  <p>Reactive UserDetailService bean that has the problem with calling repository inside a map</p>
  <pre><code>@Bean
  public PasswordEncoder passwordEncoder() {
      return PasswordEncoderFactories.createDelegatingPasswordEncoder();
  }
  
  @Bean
  public ReactiveAuthenticationManager reactiveAuthenticationManager(ReactiveUserDetailsService userDetailsService,
                                                                     PasswordEncoder passwordEncoder) {
      var authenticationManager = new UserDetailsRepositoryReactiveAuthenticationManager(userDetailsService);
      authenticationManager.setPasswordEncoder(passwordEncoder);
      return authenticationManager;
  }
  
  @Bean
  public ReactiveUserDetailsService userDetailsService(UserService userService) {
  
      return username -&gt; userService.findByUsername(username)
              .log()
              .map(u -&gt; org.springframework.security.core.userdetails.User
                      .withUsername(u.getUsername()).password(u.getPassword())                                .roles(userService.getRoles(u).toArray(String[]::new))
                      .accountExpired(!u.isActive())
                      .credentialsExpired(!u.isActive())
                      .disabled(!u.isActive())
                      .accountLocked(!u.isActive())
                      .build()
              );
  }
  </code></pre>
  <p>If I hardcoded the roles (without going to the database) it works well.</p>
  <p>I created a simple project that replicate the issue:
  <a href="https://github.com/skyglassio/repository-await/blob/master/src/main/java/com/example/demo/DevInitializer.java" rel="nofollow noreferrer">https://github.com/skyglassio/repository-await/blob/master/src/main/java/com/example/demo/DevInitializer.java</a> line 57. After <code>userMono.block();</code> is called it goes into a forever wait.</p>