Skip to content

Incorrect handling of tcp. #26

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

Closed
yihuang opened this issue Nov 5, 2019 · 2 comments
Closed

Incorrect handling of tcp. #26

yihuang opened this issue Nov 5, 2019 · 2 comments

Comments

@yihuang
Copy link

yihuang commented Nov 5, 2019

I was trying to build a postgres protocol compatible server application on top of postgres-wire, but I found that the decoder implementation is not streamlined.
For example, here(https://github.com/postgres-haskell/postgres-wire/blob/master/src/Database/PostgreSQL/Driver/Connection.hs#L174) you need to hard code the length of the buffer, and this code is actually problematic because it might only receive an arbitrary length of data.

@qnikst
Copy link

qnikst commented Dec 11, 2019

It seems to me that the observation is not quite correct, see how that work:

  1. https://github.com/postgres-haskell/postgres-wire/blob/master/src/Database/PostgreSQL/Driver/Connection.hs#L174 we pass action rReceive rawConn bs 1024 - a receive next chunk action to parseParameters.
  2. rReceive is wrapper over rawReceive that reads up n (1024 in this case) bytes and prepends bs to the value read.
  3. parseParameters calls to decodeServerMessage and passes readAction.
  4. decodeServerMessage first parses header, gets required number of bytes to read and reads them using callback.

So this protocol can read unknown in advance size of data. Unfortunately current implementation is does N copies where N is number of times driver needs to read the data, that may be suboptimal on the long messages.

Does this explanation makes sense to you? Or have I missed anything?

@yihuang
Copy link
Author

yihuang commented Dec 12, 2019

Oh, it seems correct. I guess I was taking ‘rawReceive’ as OS’s recv before.

@yihuang yihuang closed this as completed Dec 12, 2019
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