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

DATA RACE in resty.(*Client).execute() #29

Closed
iyidan opened this issue May 27, 2016 · 15 comments
Closed

DATA RACE in resty.(*Client).execute() #29

iyidan opened this issue May 27, 2016 · 15 comments
Assignees
Labels

Comments

@iyidan
Copy link

iyidan commented May 27, 2016

Hello,
I am use resty in multi-goroutine and case the DATA RACE

test.go
`package main

import (
"github.com/go-resty/resty"
"sync"
)

func main() {
w := sync.WaitGroup{}
for i := 0; i < 50; i++ {
w.Add(1)
go func() {
defer w.Done()
resty.R().Get("http://httpbin.org/get")
}()
}
w.Wait()
} go run -race test.go`

@jeevatkm jeevatkm self-assigned this May 27, 2016
@jeevatkm
Copy link
Member

Thanks for reporting. I will have a look.

@jeevatkm
Copy link
Member

@iyidan I have analyzed it, will be available in next version. If you have PR for this, feel free to send it.

@jeevatkm
Copy link
Member

@iyidan - I have taken care of it, however will do improvements later.

@jeevatkm
Copy link
Member

It will be part of v0.8 release, available in master branch.

@mrd0ll4r
Copy link

mrd0ll4r commented Aug 19, 2016

Sorry to resurrect this, just to let you know: This has broken my client as resty is not parallel anymore. I knew about the data race but it was not affecting my use case. I can fix it without much issues, but please be careful in the future about changes that change the behavior of resty so much. Thanks for the library, will keep using it! :)

@jeevatkm
Copy link
Member

@mrd0ll4r I'm sorry about you ran into issue.

Please let me know your suggestion to improve resty. I will think about keeping parallel and prevent data race in the mean time.

Looking forward to your inputs.

@mrd0ll4r
Copy link

Hard to say - you could use an RWMutex for the proxy settings etc, but you allow setting a proxy for an individual Request, so that's not going to work. Maybe make it so that requests with an explicit proxy use a separate transport and HTTP client? Hard to say for sure.

You could always just say "resty is not thread safe when modifying proxy settings (and maybe more), do thread safety in your code", which works fine for me.

@jeevatkm
Copy link
Member

@mrd0ll4r @wanghq - I thought through it. I'm planning to remove request level proxy option and mutex locking from resty.

any objections or comment?

@mrd0ll4r
Copy link

You'd still protect the top-level proxy with an RWMutex or something, right? Sounds good to me.

@jeevatkm
Copy link
Member

@mrd0ll4r that's the plan, I'm gonna give it try.

@jeevatkm
Copy link
Member

@mrd0ll4r @wanghp - mutex lock is removed from resty. I have tried RWMutex however it is not needed anymore.

I need to add note for, if resty user is modifying resty client setting from multiple goroutine/dynamically they have to use their own locking mechanism.

I have pushed changes to master. resty Performance is improved.

@wanghq
Copy link

wanghq commented Feb 27, 2017

@jeevatkm , thanks for the quick response! Looks good.

@jeevatkm
Copy link
Member

@wanghq have you tested master at your end. Please let me know your feedback.

@wanghq
Copy link

wanghq commented Mar 18, 2017

@jeevatkm , I didn't notice any issue with the master branch. Thanks again.

@jeevatkm
Copy link
Member

@wanghq Thank you for the confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants