Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(examples): Fix tower examples #624

Merged
merged 1 commit into from
May 7, 2021
Merged

Conversation

davidpdrsn
Copy link
Member

Doing

let clone = self.inner.clone();
Box::pin(async move {
    let response = clone.call(request).await?;
    Ok(response)
})

If self.inner is (or contains) a tower::buffer::Buffer might panic.

That is because cloning a Buffer drops the permit that was acquired in
poll_ready, meaning it is no longer ready and panic in call.

The solution is to use mem::replace to take the ready service and pass
that into the async block.

Fixes #545

Doing

```rust
let clone = self.inner.clone();
Box::pin(async move {
    let response = clone.call(request).await?;
    Ok(response)
})
```

If `self.inner` is (or contains) a `tower::buffer::Buffer` might panic.

That is because cloning a `Buffer` drops the permit that was acquired in
`poll_ready`, meaning it is no longer ready and panic in `call`.

The solution is to use `mem::replace` to take the ready service and pass
that into the async block.

Fixes #545
@davidpdrsn
Copy link
Member Author

This is basically #547 with my suggestions applied. OP was inactive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

example tower-client "buffer full; poll_ready must be called first"
2 participants