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

fix lost trace when multi middleware handlerFunc #167

Merged
merged 2 commits into from
Feb 6, 2024

Conversation

Ruff-nono
Copy link
Contributor

using the index of []HandlerFunc, determine if the current is the first HandlerFunc, and then handle the enhancement

#11852

@wu-sheng
Copy link
Member

Let's wait for project lead back from vacation. It should be next Monday.

@wu-sheng wu-sheng added this to the 0.4.0 milestone Jan 31, 2024
@wu-sheng wu-sheng added bug Something isn't working plugin labels Jan 31, 2024

func isFirstHandle(c interface{}) bool {
if context, ok := c.(*nativeContext); ok {
return context.index < 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Following your diagram in the comment, I think It should equal zero? Please correct me if am wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, the index is the index of HandlersChain, it is reset to -1 at the beginning of each request, and then incremented and executes the handlers[index] in the #Next().

func (c *Context) Next() {
	c.index++
	for c.index < int8(len(c.handlers)) {
		c.handlers[c.index](c)
		c.index++
	}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Then, could you help to add a comment to explain this mechanism in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@mrproliu
Copy link
Contributor

mrproliu commented Feb 6, 2024

Please update the CHANGES.md, thanks.

CHANGES.md Outdated Show resolved Hide resolved
@mrproliu mrproliu merged commit 9265c5c into apache:main Feb 6, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plugin
Projects
None yet
3 participants