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

Late and safer response writes #605

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Late and safer response writes #605

wants to merge 2 commits into from

Conversation

rafanoronha
Copy link
Contributor

Not intended to be merged - just a preview to support further discussion.

This shows how feasible might be my way to address this[1] issue in vraptor core.

Does this piece of code make sense around here?

[1] garcia-jj/vraptor-plugin-hibernate4#18

@lucascs
Copy link
Member

lucascs commented Mar 5, 2014

I don't know if the request execution is the right place to put this code. Maybe creating another interceptor for this would be better.

as the first interceptor, with the code running after the stack.next(..) call.

@rafanoronha
Copy link
Contributor Author

I wasn't sure about execution order guarantees, but you are right, probably no one is going to deal with the response before ExecuteMethodInterceptor
Beyond that, do you see this code getting merged?

@lucascs
Copy link
Member

lucascs commented Mar 5, 2014

The code makes sense, but it could break existing applications...

we should be careful testing with existing applications before shipping this.

And also write some tests for the feature ;)

@garcia-jj
Copy link
Member

I can't understand why this is necessary.

@lucascs
Copy link
Member

lucascs commented Mar 5, 2014

if we write anything to response, it will commit the response, so the status code can't change.

If any error occurs after the result.use(json()).serialize() the user will see a 200 status instead of a 500

It happens, for example, on the transaction interceptor, which commits the transaction after the controller execution.

@rafanoronha
Copy link
Contributor Author

@garcia-jj serializers write directly to response stream.
Applications using vraptor probably have code that might throw errors after serializers got called. My particular scenario is - usage of vraptor-plugin-hibernate4, the transaction interceptor commits the transaction but any database error might not be reported as an http error. It only gets reported if the response isn't flushed until that moment, and it will be flushed if more data than the response buffer size get written on it.

@rafanoronha
Copy link
Contributor Author

@lucascs Regarding the shipping of this code, in a first release we might glue it to gson (or any other) serialization. If everything goes fine then we handle other serializers.

@garcia-jj
Copy link
Member

Hmm, now I see. I'm worried about performance, because we will store many data into memory as json/xml is too long.

Ideas?

@lucascs
Copy link
Member

lucascs commented Mar 6, 2014

If we ship we should do it on all serializers.

@rafanoronha
Copy link
Contributor Author

just realized a second approach for the issue would be deprecating Results methods like json() in favor of interceptors like that one based on @Json. These interceptors should run close to the end of the request pipeline. Also any transaction management interceptor should be able to commit before they get executed.

There is also a third approach - recommending users of the serializers to adjust the response buffer size of the servlet container to a value that fits their response payloads. This can even be made programatically and it actually solves the problem.

@csokol
Copy link

csokol commented Mar 6, 2014

I don't know if this is actually possible, but, instead of caching the
content of the response, we could cache only the objects that should be
serialized, and serialize them later in a interceptor, I think this would
solve the memory issue that Otavio mentioned.

Chico Sokol

On Thu, Mar 6, 2014 at 7:01 AM, rafanoronha notifications@github.comwrote:

just realized that a different approach for the issue would be deprecating
Results methods like json() in favor of interceptors like that one based
on @JSON. These interceptors should run close to the end of the request
pipeline. Also any transaction management interceptor should be able to
commit before they get executed.

Reply to this email directly or view it on GitHubhttps://github.com//pull/605#issuecomment-36840611
.

@lucascs
Copy link
Member

lucascs commented Mar 6, 2014

If we go with the csokol solution, we could add a .commit() method on Serialization instead of creating another component to handle lazy writes.

what do you think?

@rafanoronha
Copy link
Contributor Author

Yeah sounds like the better approach so far. I'll try to give it a shot

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

Successfully merging this pull request may close these issues.

4 participants