Stored saga json state can cause custom tooling parsing issues on SQL Server #1331
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When updating saga state where the serialized json is smaller than whats already present in the database the updated payload is corrupted.
Expected Behavior
When string or array values are updated with shorted values that there will be not data left from previous versions:
Observed Behavior
In version 7.0.3 data of the previous version will remain in the database column for SQL server.
How to reproduce
111
)11
)Root cause
7.0.3 introduced logic to set the SQL command parameter length to either 4000 or -1 for strings and arrays. This to ensure that SQL server will not create a new query plan so it will use the query cache.
Unfortunately, this has a side effect that SQL Server does not remove trailing data in an existing column for INSERT/UPDATE if the new value is shorter than the previous.
Resolution
The length should only be set to 4000/-1 for SELECT queries
Versions
NServiceBus.Persistence.Sql
7.0.3Who's affected
Only version 7.0.3 is affected when using SQL Server
Additional Information