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

Multiple fixes for http libraries #1832

Merged
merged 1 commit into from
Jul 6, 2023
Merged

Conversation

aarroyoc
Copy link
Sponsor Contributor

  • use reqwest for http_open (still uses Hyper underneath)
  • use Hyper 1.0.0-rc3 for server
  • Modify all internal handling of server

In general we try to use less parts of Tokio (which can be problematic right now and actually it introduced a complex data race) while preparing Scryer to use Hyper 1.0 once it reaches final state. We use reqwest instead of Hyper for the client because in Hyper 1.0 they removed the high-level Client module we were using, reqwest is from the same authors, higher level but for our use case, still fine.

Note that none of this changes the external API that http_open and http_server define.

close(ResponseStream)
chars_utf8bytes(ResponseText, ResponseBytes),
catch(
call_cleanup(maplist(put_byte(ResponseStream), ResponseBytes),close(ResponseStream)),
Copy link
Contributor

@triska triska Jun 19, 2023

Choose a reason for hiding this comment

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

This is very expensive, since it writes every byte individually. Is there a way to use format/3 or phrase_to_stream/2 for this? It seems that should work.

Note that chars_utf8bytes/2 is also very expensive, and forfeits the compact internal string representation!

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

This was actually what I needed to change in order to not generate corrupted responses (as you might remember from IRC). However, I'm going to try to change the type of the stream as you told me

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you a lot! There could very well be another, unrelated, mistake hidden in Scryer's stream or string handling that is now only overshadowed by this workaround. format/3 or phrase_to_stream/2 should work, and if not, then we should correct this! I think a good test case tries, over and over, to send and receive messages, for many hours.

@triska
Copy link
Contributor

triska commented Jun 19, 2023

Thank you a lot for working on this! I added a comment for Prolog code which seems not ideal.

catch(
call_cleanup(format(ResponseStream, "~s", [ResponseText]),close(ResponseStream)),
error(existence_error(stream, _), _),
true
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to suppress this exception if it occurs?

It seems it could be interesting to know whether sending failed!

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

This might happen if the HTTP request was canceled by the client. At that point, we can safely ignore the error, there's no point in sending it again since we lost the connection, and don't stop the server.

@infogulch
Copy link
Contributor

I made some changes to the build definitions to fix the issue that caused the last build to fail. You can trigger the build again if you push any commit to your branch.

* use reqwest for http_open (still uses Hyper underneath)
* use Hyper 1.0.0-rc3 for server
* Modify all internal handling of server
@mthom
Copy link
Owner

mthom commented Jul 5, 2023

@aarroyoc Thanks for these fixes, should I merge them now?

@aarroyoc
Copy link
Sponsor Contributor Author

aarroyoc commented Jul 6, 2023

Yes! I've been using it to develop my new blog and is very stable. I still want to add more things as I need them but I can open another PR. The only "ugly" thing is that it uses a non-stable version of Hyper (1.0-RC3) and uses reqwest which bundles another Hyper (0.14). So the final binary has two Hypers... In theory, when Hyper 1.0 goes stable, reqwest should upgrade too and the dependency will be shared but I can't give you an estimation of how much time it is until that.

@mthom mthom merged commit fd70d89 into mthom:master Jul 6, 2023
8 checks passed
@aarroyoc aarroyoc deleted the http-fixes branch July 7, 2023 15:41
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.

None yet

4 participants