pires / go-proxyproto

A Go library implementation of the PROXY protocol, versions 1 and 2.
Apache License 2.0
478 stars 107 forks source link

protocol: fixed deadline datarace #86 #87

Closed mschneider82 closed 2 years ago

mschneider82 commented 2 years ago

Fixed the race by using atomic.Value instead of unprotected time.Time

It was nessasarry to restructure the Conn struct because of this:

struct of size 80 could be 72 (fieldalignment)

coveralls commented 2 years ago

Coverage Status

Coverage increased (+0.02%) to 95.563% when pulling b4887c17f36348fda09047885675ca4c3002ae9d on mschneider82:master into 2e44d7a76a851d66890ab341403253afae5caac2 on pires:main.

pires commented 2 years ago

Thanks @mschneider82! Could you please turn on race mode for testing to prove this works (as it looks it does)?

pires commented 2 years ago

TIL https://medium.com/@sebassegros/golang-dealing-with-maligned-structs-9b77bacf4b97

mschneider82 commented 2 years ago

I have added a nil check for atomic.Value with default time.Time{} (no deadline timeout) because TestPassthrough failed. In case no deadline was set

mschneider82 commented 2 years ago

@pires i have tested it local with -race on. i will add -race to github actions

mschneider82 commented 2 years ago

done, ready for review & merge