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

Disable lineLimitReader when handle BDAT data #139

Merged
merged 7 commits into from
Mar 24, 2021

Conversation

norguhtar
Copy link
Contributor

We can fix this problem #81 (comment)

By add checkflag to disable limit checking on handle BDAT data

conn.go Outdated Show resolved Hide resolved
conn.go Outdated Show resolved Hide resolved
conn.go Outdated
@@ -753,6 +757,7 @@ func (c *Conn) handleBdat(arg string) {
}

c.reset()
c.lineLimitReader.LineLimit = prevLineLimit
Copy link
Owner

@emersion emersion Mar 22, 2021

Choose a reason for hiding this comment

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

Instead of duplicating these statements, can we maybe use defer here?

prevLineLimit := c.lineLimitReader.LineLimit
c.lineLimitReader.LineLimit = 0
defer func() {
	c.lineLimitReader.LineLimit = prevLineLimit
}()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I try it. But it not worked as expected.

Copy link
Owner

Choose a reason for hiding this comment

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

Hm, what went wrong exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It just don't work. If i'm add defer and first chunk handle return error TooLongLine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, what went wrong exactly?

I found problem. This code

defer func() {
	c.lineLimitReader.LineLimit = prevLineLimit
}()

Run go routine and this can run defer and next handle at same time. I fix that with this code

	recover := func() {
		c.lineLimitReader.LineLimit = prevLineLimit
	}
	defer recover()

this fix problem same time running defer goroutine and next handleBdat

Copy link
Owner

Choose a reason for hiding this comment

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

I don't really understand why it doesn't work without the intermediary variable. It definitely should.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It worked. But defer run in goroutine. This goroutine code

func() {
	c.lineLimitReader.LineLimit = prevLineLimit
}()

And some time next handleBdat running before running defer. After this when we try copy chunk

 io.Copy(c.bdatPipe, chunk)

Read return ErrTooLongLine

Copy link
Owner

Choose a reason for hiding this comment

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

defer doesn't run in a separate goroutine...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okey i'm research problem deeper and create new fix. First we should't restore limit before got BDAT LAST command. It's broke In some cases and return error ToooLongTime. For example read next BDAT command. I'm just put restore lineLimit in last condition and this fix problem.

Copy link
Owner

Choose a reason for hiding this comment

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

Oh you're right, if the BDAT transfer is still ongoing, we shouldn't restore the limit.

conn.go Outdated Show resolved Hide resolved
@emersion
Copy link
Owner

emersion commented Mar 24, 2021

Can we also restore the limit in case io.Copy fails?

@norguhtar
Copy link
Contributor Author

Add recover on io.Copy fails

Copy link
Owner

@emersion emersion left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your patience!

@emersion emersion merged commit f92bf7f into emersion:master Mar 24, 2021
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

2 participants