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

JSON Serializer ArgumentOutOfRangeException #528

Closed
CampsiteHelper opened this issue Apr 6, 2017 · 6 comments
Closed

JSON Serializer ArgumentOutOfRangeException #528

CampsiteHelper opened this issue Apr 6, 2017 · 6 comments
Assignees

Comments

@CampsiteHelper
Copy link

DTO:

[Route("/api/log/{lines}", "GET")]
	public class logRequest
	{
		public int lines { get; set; }	
	}

Service:

[RequiredRole("Admin")]
        public Object Any(logRequest request)
		{

			var rootAppender = ((Hierarchy)LogManager.GetRepository())
										 .Root.Appenders.OfType<FileAppender>()
										 .FirstOrDefault();

			string filename = rootAppender != null ? rootAppender.File : string.Empty;

			String s = Util.tail(filename, request.lines, System.Text.Encoding.ASCII);
			return s.Split('\n').ToList();



		}

Call:
http://127.0.0.1:8081/api/log/25?format=json

(Note, xml or html do not have the same issue)

Result:
....(most of the appropriate JSON response.....INFO 2017-04-06 11:35:58,026 3571ms Util getRoles - Got 1 groups","DEBUG 2017-04-06 11:35:58,029 3574ms Util OnAuthenticated - Loaded user upon authentication","{"ResponseStatus":{"ErrorCode":"ArgumentOutOfRangeException","Message":"Specified argument was out of the range of valid values.\nParameter name: offset","StackTrace":" at System.Web.HttpResponseStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x00031] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.Web/System.Web/HttpResponseStream.cs:459 \n at ServiceStack.Text.DirectStreamWriter.Write (System.String s) [0x00034] in <5d202dc8fb8f479ba5bbea3e08634e28>:0 \n at ServiceStack.Text.Json.JsonUtils.WriteString (System.IO.TextWriter writer, System.String value) [0x0002c] in <5d202dc8fb8f479ba5bbea3e08634e28>:0 \n at ServiceStack.Text.Json.JsonTypeSerializer.WriteString (System.IO.TextWriter writer, System.String value) [0x00000] in <5d202dc8fb8f479ba5bbea3e08634e28>:0 \n at ServiceStack.Text.Common.WriteLists.WriteListString (ServiceStack.Text.Common.ITypeSerializer serializer, System.IO.TextWriter writer, System.Collections.Generic.List1[T] list) [0x00023] in <5d202dc8fb8f479ba5bbea3e08634e28>:0 \n at ServiceStack.Text.Common.WriteLists.WriteListString (ServiceStack.Text.Common.ITypeSerializer serializer, System.IO.TextWriter writer, System.Object list) [0x00000] in <5d202dc8fb8f479ba5bbea3e08634e28>:0 \n at ServiceStack.Text.Common.WriteLists2+<>c[T,TSerializer].b__5_0 (System.IO.TextWriter w, System.Object x) [0x00000] in <5d202dc8fb8f479ba5bbea3e08634e28>:0 \n at ServiceStack.Text.JsonSerializer.SerializeToStream (System.Object value, System.Type type, System.IO.Stream stream) [0x00012] in <5d202dc8fb8f479ba5bbea3e08634e28>:0 \n at ServiceStack.Text.JsonSerializer.SerializeToStream[T] (T value, System.IO.Stream stream) [0x00037] in <5d202dc8fb8f479ba5bbea3e08634e28>:0 \n at ServiceStack.Serialization.JsonDataContractSerializer.SerializeToStream[T] (T obj, System.IO.Stream stream) [0x00050] in :0 \n at ServiceStack.Host.ContentTypes+<>c.b__21_1 (ServiceStack.Web.IRequest r, System.Object o, System.IO.Stream s) [0x00000] in :0 \n at ServiceStack.Host.ContentTypes+<>c__DisplayClass20_0.b__0 (ServiceStack.Web.IRequest httpReq, System.Object dto, ServiceStack.Web.IResponse httpRes) [0x0000e] in :0 \n at ServiceStack.HttpResponseExtensionsInternal.WriteToResponse (ServiceStack.Web.IResponse response, System.Object result, ServiceStack.Web.ResponseSerializerDelegate defaultAction, ServiceStack.Web.IRequest request, System.Byte[] bodyPrefix, System.Byte[] bodySuffix) [0x003f0] in :0 ","Errors":[{"ErrorCode":"ArgumentOutOfRangeException","FieldName":"offset","Message":"Specified argument was out of the range of valid values.\n"}]}}

@CampsiteHelper
Copy link
Author

I would also note - this problem goes away if we wrap the return in ToOptimizedResult, and also the Serializer performance on Mono has gone from great to horrendous as of this problem. The problem did not (appear) to begin after any ServiceStack, Mono/Xamarin, or MacOS updates specifically.

@xplicit xplicit self-assigned this Apr 6, 2017
@xplicit
Copy link

xplicit commented Apr 6, 2017

Can you show what is the content of string s before the returning from service? I can't reproduce the issue with mono 4.8.0 and ServiceStack 4.5.8

I used following code for generating resulting string array:

        public object Any(logRequest request)
	{
            string[] s = new string[25];

            for (int i = 0; i < s.Length; i++) {
                s[i] = "INFO " + i.ToString();
            }
            return s.ToList();
        } 

@CampsiteHelper
Copy link
Author

CampsiteHelper commented Apr 8, 2017

sure, s would generally be fairly large, its log4net log tail, like attached

log.txt

And come to think about it, the other services that are affected generally have fairly large payloads (sometimes a MB or more)

@xplicit
Copy link

xplicit commented Apr 9, 2017

I still can't reproduce it with this file. I also tried to create file from this log with 30Mb length, but it returns without issues.

public object Any(logRequest request)
{
    string s = File.ReadAllText ("log.txt");
    return s.Split('\n').ToList();
}

But after looking into mono sources I think I found what can raise the exception. This line does not allow to pass empty buffer, so I fix it in this commit.

This fix will be available on MyGet as soon as we finish migrating CI and ServiceStack projects to VS 2017 format.

@xplicit
Copy link

xplicit commented Apr 11, 2017

@CampsiteHelper we pushed latest changes to MyGet, can you check does this fix resolve the issue?

@xplicit
Copy link

xplicit commented Apr 17, 2017

As this should be fixed, I close it. If issue is still exists feel free to reopen it again.

@xplicit xplicit closed this as completed Apr 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants