Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Formatting and parsing changes to JsonString - #41940

Merged
stephentoub merged 15 commits into
dotnet:masterfrom
khellang:json-string
Nov 1, 2019
Merged

stephentoub merged 15 commits into
dotnet:masterfrom
khellang:json-string

Conversation

@khellang

Copy link
Copy Markdown
Member

This consolidates parsing and formatting between Json[Reader|Writer] and JsonString and fixes some bugs in the process.

Fixes #41706
Fixes #41779

@khellang
khellang force-pushed the json-string branch 2 times, most recently from 1936ef4 to 793cdc9 Compare October 22, 2019 12:26
@ahsonkhan ahsonkhan added this to the 5.0 milestone Oct 24, 2019
@ahsonkhan
ahsonkhan requested a review from joperezr October 24, 2019 06:06

@ahsonkhan ahsonkhan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Some nits, but otherwise looks good.

@khellang

Copy link
Copy Markdown
Member Author

Looks like replacing MaximumFormatDateTimeOffsetLength with MaximumFormatDateTimeLength for the DateTime methods broke TrimDateTimeOffset. I'll look into it.

@khellang

khellang commented Oct 25, 2019 •

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 41940 in repo dotnet/corefx

@ahsonkhan

Copy link
Copy Markdown

Looks like unrelated/intermittent infra failure. I have re-run the leg.

allConfigurations-Windows_NT-Debug-x64-Windows.10.Amd64.ClientRS5.Open

https://helix.dot.net/api/2019-06-17/jobs/5d4f0f39-bc52-4365-af19-e011ec1f7502/workitems/System.Reflection.Emit.Lightweight/console

  Restore completed in 29.91 sec for C:\dotnetbuild\work\5d4f0f39-bc52-4365-af19-e011ec1f7502\Work\f807e6bf-cce8-4ed9-9a5f-bfddaee6eef0\Unzip\netcoreapp1.0\project.csproj.
  Failed to download package 'runtime.any.System.Diagnostics.Tools.4.3.0' from 'https://dotnetfeed.blob.core.windows.net/dotnet-core/flatcontainer/runtime.any.system.diagnostics.tools/4.3.0/runtime.any.system.diagnostics.tools.4.3.0.nupkg'.
  No such host is known.
  Failed to download package 'runtime.any.System.Diagnostics.Tools.4.3.0' from 'https://dotnetfeed.blob.core.windows.net/dotnet-core/flatcontainer/runtime.any.system.diagnostics.tools/4.3.0/runtime.any.system.diagnostics.tools.4.3.0.nupkg'.
  No such host is known.
C:\dotnetbuild\work\5d4f0f39-bc52-4365-af19-e011ec1f7502\Payload\tools\sdk\3.0.100\NuGet.targets(123,5): error : Failed to download package 'runtime.any.System.Diagnostics.Tools.4.3.0' from 'https://dotnetfeed.blob.core.windows.net/dotnet-core/flatcontainer/runtime.any.system.diagnostics.tools/4.3.0/runtime.any.system.diagnostics.tools.4.3.0.nupkg'. [C:\dotnetbuild\work\5d4f0f39-bc52-4365-af19-e011ec1f7502\Work\f807e6bf-cce8-4ed9-9a5f-bfddaee6eef0\Unzip\netcoreapp1.1\project.csproj]
C:\dotnetbuild\work\5d4f0f39-bc52-4365-af19-e011ec1f7502\Payload\tools\sdk\3.0.100\NuGet.targets(123,5): error : No such host is known. [C:\dotnetbuild\work\5d4f0f39-bc52-4365-af19-e011ec1f7502\Work\f807e6bf-cce8-4ed9-9a5f-bfddaee6eef0\Unzip\netcoreapp1.1\project.csproj]

@dotnet/dnceng

@MattGal

MattGal commented Oct 25, 2019 •

Copy link
Copy Markdown
Member

Looks like unrelated/intermittent infra failure. I have re-run the leg.

allConfigurations-Windows_NT-Debug-x64-Windows.10.Amd64.ClientRS5.Open

https://helix.dot.net/api/2019-06-17/jobs/5d4f0f39-bc52-4365-af19-e011ec1f7502/workitems/System.Reflection.Emit.Lightweight/console

  Restore completed in 29.91 sec for C:\dotnetbuild\work\5d4f0f39-bc52-4365-af19-e011ec1f7502\Work\f807e6bf-cce8-4ed9-9a5f-bfddaee6eef0\Unzip\netcoreapp1.0\project.csproj.
  Failed to download package 'runtime.any.System.Diagnostics.Tools.4.3.0' from 'https://dotnetfeed.blob.core.windows.net/dotnet-core/flatcontainer/runtime.any.system.diagnostics.tools/4.3.0/runtime.any.system.diagnostics.tools.4.3.0.nupkg'.
  No such host is known.
  Failed to download package 'runtime.any.System.Diagnostics.Tools.4.3.0' from 'https://dotnetfeed.blob.core.windows.net/dotnet-core/flatcontainer/runtime.any.system.diagnostics.tools/4.3.0/runtime.any.system.diagnostics.tools.4.3.0.nupkg'.
  No such host is known.
C:\dotnetbuild\work\5d4f0f39-bc52-4365-af19-e011ec1f7502\Payload\tools\sdk\3.0.100\NuGet.targets(123,5): error : Failed to download package 'runtime.any.System.Diagnostics.Tools.4.3.0' from 'https://dotnetfeed.blob.core.windows.net/dotnet-core/flatcontainer/runtime.any.system.diagnostics.tools/4.3.0/runtime.any.system.diagnostics.tools.4.3.0.nupkg'. [C:\dotnetbuild\work\5d4f0f39-bc52-4365-af19-e011ec1f7502\Work\f807e6bf-cce8-4ed9-9a5f-bfddaee6eef0\Unzip\netcoreapp1.1\project.csproj]
C:\dotnetbuild\work\5d4f0f39-bc52-4365-af19-e011ec1f7502\Payload\tools\sdk\3.0.100\NuGet.targets(123,5): error : No such host is known. [C:\dotnetbuild\work\5d4f0f39-bc52-4365-af19-e011ec1f7502\Work\f807e6bf-cce8-4ed9-9a5f-bfddaee6eef0\Unzip\netcoreapp1.1\project.csproj]

@dotnet/dnceng

There's not much we can do here. The machine in question only lived for about an hour and only ran 17 tests. It even ran (and passed) tests from your same run seconds after this one: https://helix.dot.net/api/2019-06-17/jobs/5d4f0f39-bc52-4365-af19-e011ec1f7502/workitems/System.Threading.AccessControl/console ... so the conclusion I'd draw here is that there was a few-seconds DNS burp with that storage account, leading to the test failing. I'd recommend adding a retry or two here given when these tests run on a scaled out scaleset there's a bunch of fast-network machines all trying to restore from this feed at once.

@JohnTortugo

Copy link
Copy Markdown
Contributor

@dotnet/dnceng

This looks like a point in time network failure.

@MattGal

MattGal commented Oct 25, 2019

Copy link
Copy Markdown
Member

@dotnet/dnceng

This looks like a point in time network failure.

not a network failure, an Azure storage service failure IMO.

@layomia layomia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please update the JsonStringTests as well.
I'll update the DateTime(Offset) length constants in a follow up.

Otherwise, LGTM.

return false;
}

Debug.Assert(JsonReaderHelper.GetUtf8ByteCount(source) <= JsonConstants.StackallocThreshold);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What guarantees this? What if the source is erroneously made up of MaximumEscapedDateTimeOffsetParseLength Unicode characters?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The IsValidDateTimeOffsetParseLength check above (#41940 (comment)):

In fact, the above check using IsValidDateTimeOffsetParseLength guarantees its between 10 and 6*(33+16-7), i.e. 252.

JsonConstants.StackallocThreshold is 256 😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, I see what you mean now. If the chars in the span expands to more UTF8 bytes?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good point. We should add a test case for that to make sure subsequent changes don't fall into the same issue.

That said, instead of calling JsonReaderHelper.GetUtf8ByteCount, can we just assume the worst case, and do:

int length = source.Length * JsonConstants.MaxExpansionFactorWhileTranscoding;

In most cases, the length will still be less than 256, and we avoid the double read over the source span.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Opened #42574

@stephentoub
stephentoub merged commit 21fd4d2 into dotnet:master Nov 1, 2019
@stephentoub

Copy link
Copy Markdown
Member

Thanks.

@khellang
khellang deleted the json-string branch November 2, 2019 13:04
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Pull duplicated code into JsonWriterHelper

* Add helpers for parsing and formatting ISO dates

* Update tests to expect new format

* Use new helpers in JsonString methods

* Rename methods

* Check for valid parse length

* Use AsSpan extension to work around missing implicit operators on netfx

* More netfx workarounds

* Use constant for stackalloc length

* Add back temp span to avoid writing too much when trimming

* Move IsValidDateTimeOffsetParseLength to JsonHelpers

* Always use StackallocThreshold instead of calling GetUtf8ByteCount

* Remove redundant length checks done by IsValidDateTimeOffsetParseLength

* Adapt test pattern from Utf8JsonWriterTests

* Revert "Always use StackallocThreshold instead of calling GetUtf8ByteCount"

This reverts commit dotnet/corefx@0d29b64.


Commit migrated from dotnet/corefx@21fd4d2
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.

JsonStringTests.TestDateTimeOffset test failure JsonString node doesn't round-trip DateTimeOffset correctly

7 participants