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

Panic when pulling cable on RTU device #66

Closed
Foelsgaard opened this issue Oct 21, 2020 · 2 comments · Fixed by #67
Closed

Panic when pulling cable on RTU device #66

Foelsgaard opened this issue Oct 21, 2020 · 2 comments · Fixed by #67

Comments

@Foelsgaard
Copy link

Foelsgaard commented Oct 21, 2020

Pulling the cable on a device while a request is processing results in a panic at tokio-modbus/src/service/rtu.rs:60:

    async fn call(&mut self, req: Request) -> Result<Response, Error> {
        let disconnect = req == Request::Disconnect;
        let req_adu = self.next_request_adu(req, disconnect);
        let req_hdr = req_adu.hdr;

        self.service.send(req_adu).await?;
        let res_adu = self.service.next().await.unwrap()?; // This is where it panics

        match res_adu.pdu {
            ResponsePdu(Ok(res)) => verify_response_header(req_hdr, res_adu.hdr).and(Ok(res)),
            ResponsePdu(Err(err)) => Err(Error::new(ErrorKind::Other, err)),
        }
    }

This seems to be a regression from v0.3.5 where it would instead return a broken pipe error.

It looks like it should be a pretty easy fix. Just map the None to some error and return that.

@flosse
Copy link
Member

flosse commented Oct 23, 2020

@Foelsgaard thanks for reporting!
Hopefully I'll be able to fix that soon.

@flosse flosse self-assigned this Oct 23, 2020
@flosse flosse added this to the v0.4.1 milestone Oct 23, 2020
@Foelsgaard
Copy link
Author

@flosse Great! Thank you so much! :)

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

Successfully merging a pull request may close this issue.

2 participants