Skip to content

Conversation

@SarahFrench
Copy link
Member

@SarahFrench SarahFrench commented Sep 19, 2025

This PR moves some fixes to the radek/pss-read-write branch out of #37323

I tested the process of initialising a working directory end to end using the pss provider and our changes to the terraform-plugin-go repo, and in the process made these changes to the Core-side of ReadStateBytes.

The main changes in this PR are:

  • Being clear that the io.EOF sentinel error is not expected to be accompanied with any chunk information, i.e. no bytes and no diagnostics.
  • Adding a call to CloseSend to close the stream, if reading the state didn't encounter any grpc errors or custom error diagnostics from the provider.

Target Release

N/A

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@SarahFrench SarahFrench changed the title Sarah/pss read write updates Sarah's updates to radek/pss-read-write Sep 19, 2025
Comment on lines 1517 to 1521
if err == io.EOF {
// End of stream, we're done
if chunk != nil {
// TODO: The EOF error could be just returned alongside the last chunk?
resp.Diagnostics = resp.Diagnostics.Append(convert.ProtoToDiagnostics(chunk.Diagnostics))
}
// No chunk is returned alongside an EOF.
// And as EOF is a sentinel error it isn't wrapped as a diagnostic.
break
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see this comment in our terraform-plugin-go PR explaining why we will never see a chunk alongside the EOF error here: https://github.com/hashicorp/terraform-plugin-go/pull/563/files#r2362735975

@SarahFrench SarahFrench marked this pull request as ready for review September 19, 2025 12:32
@SarahFrench SarahFrench requested a review from a team as a code owner September 19, 2025 12:32
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for all the work and the tests! 👍🏻

@SarahFrench SarahFrench merged commit a578ac2 into radek/pss-read-write Sep 19, 2025
15 checks passed
@SarahFrench SarahFrench deleted the sarah/pss-read-write-updates branch September 19, 2025 13:29
radeksimko pushed a commit that referenced this pull request Sep 19, 2025
* Update code to not expect a chunk when EOF encountered

* Return early if any grpc errors are encountered during ReadStateBytes

* Close the stream with CloseSend once everything's read without error. Add test case about handling grpc errors from CloseSend.

* Fix test case about warnings: We would expect to receive a chunk with data alongside the warning and have a normal closing of the stream after EOF

* Add log line, remove unneeded type info
radeksimko pushed a commit that referenced this pull request Sep 23, 2025
* Update code to not expect a chunk when EOF encountered

* Return early if any grpc errors are encountered during ReadStateBytes

* Close the stream with CloseSend once everything's read without error. Add test case about handling grpc errors from CloseSend.

* Fix test case about warnings: We would expect to receive a chunk with data alongside the warning and have a normal closing of the stream after EOF

* Add log line, remove unneeded type info
radeksimko pushed a commit that referenced this pull request Sep 25, 2025
* Update code to not expect a chunk when EOF encountered

* Return early if any grpc errors are encountered during ReadStateBytes

* Close the stream with CloseSend once everything's read without error. Add test case about handling grpc errors from CloseSend.

* Fix test case about warnings: We would expect to receive a chunk with data alongside the warning and have a normal closing of the stream after EOF

* Add log line, remove unneeded type info
radeksimko added a commit that referenced this pull request Sep 26, 2025
* Implement ReadStateBytes + WriteStateBytes

* [WIP] -  Testing ReadStateBytes and WriteStateBytes (#37464)

* Fix nil pointer error

* Add WIP test for ReadStateBytes

* Move test mock to separate testing file

* Update mock to send unexpected EOF when there's a problem returning data and it's not a true EOF

* Add test case for when length != expected length

* Add test for when trying to read state from a store type that doesn't exist

* Change symbol names to lowercase

* Add ability to force a diagnostic to be returned from `mockReadStateBytesClient`'s `Recv` method

* Add test showing error diagnostics raised by the ReadStateBytes client are returned

* Add missing header

* Simplify mock by using an embedded type

* Rename `mockOpts` to `mockReadStateBytesOpts`

* Update existing tests to assert what arguments are passed to the RPC method call

* Add mock WriteStateBytesClient which uses `go.uber.org/mock/gomock` to enable assertions about calls to Send

* Add a test for WriteStateBytes that makes assertions about calls to the Send method

* Update test case to explicitly test writing data smaller than the chunk size

* Implement chunking in WriteStateBytes, add test case to assert expected chunking behaviour

* Add generated mock for Provider_WriteStateBytesClient in protocol v6

* Update tests to use new `MockProvider_WriteStateBytesClient`, remove handwritten mock

* Update code comments in test

* Add tests for diagnostics and errors returned during WriteStateBytes

* Add generated mock for Provider_ReadStateBytesClient in protocol v6, replace old mock

* Add test case for grpc errors in ReadStateBytes, fix how error is returned

* Typo in comment

* Add missing warning test, rename some test cases

* Update proto file definition of Read/WriteStateBytes RPCs (#37529)

* Update Read/WriteStateBytes RPCs to match hashicorp/terraform-plugin-go#531

* Run `make protobuf`

* Run `make generate`

* Update use of `proto.ReadStateBytes_ResponseChunk` in tests

* Fix how diagnostics are handled alongside EOF error, update ReadStateBytes test

* More fixes - test setup was incorrect

I think? I assume that a response would be returned full of zero-values when EOF is encountered.

* WIP - avoid crash if chunk is nil

* Sarah's updates to radek/pss-read-write (#37642)

* Update code to not expect a chunk when EOF encountered

* Return early if any grpc errors are encountered during ReadStateBytes

* Close the stream with CloseSend once everything's read without error. Add test case about handling grpc errors from CloseSend.

* Fix test case about warnings: We would expect to receive a chunk with data alongside the warning and have a normal closing of the stream after EOF

* Add log line, remove unneeded type info

* Implement configurable state chunk size

* handle metadata in WriteStateBytes correctly

* validate chunk sizes received from provider

* ReadStateBytes: avoid early return on warnings

---------

Co-authored-by: Sarah French <[email protected]>
@github-actions
Copy link
Contributor

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 20, 2025
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.

2 participants