Skip to content

Conversation

@theobarkerh
Copy link
Contributor

Possible fix to #708

ReadFileRecordRequest does not include an implementation of get_response_pdu_size() so the rtu_framer completes prior to a full response received. Causes many errors during a file read operation.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 1, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@dhoomakethu
Copy link
Contributor

I haven't used the ReadFileRecordRequest so just dropping the spec for future reference
image

@theobarkerh
Copy link
Contributor Author

theobarkerh commented Feb 2, 2022

Is this ready to merge? I.e., the failed checks are from upstream code unrelated to this pull request.

@theobarkerh
Copy link
Contributor Author

Suggestions on how to resolve??

@christiansandberg
Copy link
Contributor

I really think pymodbus should use the response data length (byte after the function code) instead to determine how many bytes to read next. I don't think you should rely on the server returning the requested length because some files may behave like in a file system where reading past EOF will return less bytes than requested.

@theobarkerh
Copy link
Contributor Author

I really think pymodbus should use the response data length (byte after the function code) instead to determine how many bytes to read next. I don't think you should rely on the server returning the requested length because some files may behave like in a file system where reading past EOF will return less bytes than requested.

Have you tried transferring files from devices produced by multiple vendors?

@christiansandberg
Copy link
Contributor

This change will for sure break compatibility with certain devices. The method used currently, although unstable, is correct since it doesn't make assumptions about the response length based on the request. I'm guessing this was the reason why this method is missing from file records in the first place.

Using the byte count instead will not change the current behavior, as long as the byte count given by the device is correct of course.

@theobarkerh
Copy link
Contributor Author

This change will for sure break compatibility with certain devices. The method used currently, although unstable, is correct since it doesn't make assumptions about the response length based on the request. I'm guessing this was the reason why this method is missing from file records in the first place.

Using the byte count instead will not change the current behavior, as long as the byte count given by the device is correct of course.

The current method is unusable. Thus the PR.
This was the best solution I found based on my limited knowledge of the code base and specification. Please add code changes you would suggest to the diff on this PR.

@janiversen
Copy link
Collaborator

@theobarkerh can you please test against the current dev, there have been multiple corrections, that leads me to believe that your PR might no longer be relevant, however you are the best to say so.

@theobarkerh
Copy link
Contributor Author

@theobarkerh can you please test against the current dev, there have been multiple corrections, that leads me to believe that your PR might no longer be relevant, however you are the best to say so.

Thanks Jan! I'll test it as soon as a get a break to do that. Hopefully today or tomorrow.

@janiversen janiversen force-pushed the 708-get_response_pdu_size branch 3 times, most recently from 67c12a0 to 7f48b1e Compare May 27, 2022 18:15
@theobarkerh
Copy link
Contributor Author

@janiversen, I was able to test with the code which tripped over the implementation in the last release.
The 'dev' branch ran much better. I didn't have a chance to instrument it to verify that the timing is optimal.

@janiversen janiversen force-pushed the 708-get_response_pdu_size branch from 7f48b1e to 9fc62e2 Compare May 27, 2022 18:23
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
11.7% 11.7% Duplication

@theobarkerh
Copy link
Contributor Author

@janiversen, I was able to test with logging.setLevel(logging.DEBUG) and compare this implementation with 'dev'. They do appear to have the same efficiency.

@janiversen
Copy link
Collaborator

I am confused you talk about efficiency, but your pr is about errors when reading files, I do not see the relation.

I never said that dev was more efficient, but partial reads have been reduced.

@theobarkerh
Copy link
Contributor Author

theobarkerh commented May 27, 2022

I am confused you talk about efficiency, but your pr is about errors when reading files, I do not see the relation.

I never said that dev was more efficient, but partial reads have been reduced.

Partial reads [requiring retries] is the efficiency problem to which I referred. Thank you. As you noted, this PR may not add any improvement over the current 'dev' implementation.

@janiversen
Copy link
Collaborator

Ok, but it still makes sense to have a correct get_response_pdu_size()

@janiversen janiversen merged commit 5f2cf59 into pymodbus-dev:dev May 28, 2022
@christiansandberg
Copy link
Contributor

Unfortunately this will cause communication with our devices to fail since the size indication encoded in the response gets ignored. I know that the specification says that there probably should be a relation between request and response but the protocol also has an explicit byte count for the actual response size and this should take priority over any implicit calculations.

One example of a use case where the spec is not always followed is when transferring large files using Write File Record. The response should contain the exact same data as in the request but this wastes a lot of bandwidth and many implementations choose to not send the data back. The Modbus protocol supports this behavior both by indicating the byte size and the underlying framing layer.

In this regard the previous behavior was better since it was more flexible in response sizes it accepted. Now it will cause a timeout on perfectly valid responses.

janiversen added a commit that referenced this pull request May 28, 2022
janiversen added a commit that referenced this pull request May 28, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants