Merge pull request #3922 from BurtonQin/bug-1-2-3-inconsistent-field-protection
cache, context, session: add lock to fix inconsistent field protection
This commit is contained in:
		
						commit
						8f3d1c5f42
					
				
							
								
								
									
										3
									
								
								cache/memory.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								cache/memory.go
									
									
									
									
										vendored
									
									
								
							| @ -218,9 +218,12 @@ func (bc *MemoryCache) vacuum() { | |||||||
| 	} | 	} | ||||||
| 	for { | 	for { | ||||||
| 		<-time.After(bc.dur) | 		<-time.After(bc.dur) | ||||||
|  | 		bc.RLock() | ||||||
| 		if bc.items == nil { | 		if bc.items == nil { | ||||||
|  | 			bc.RUnlock() | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
|  | 		bc.RUnlock() | ||||||
| 		if keys := bc.expiredKeys(); len(keys) != 0 { | 		if keys := bc.expiredKeys(); len(keys) != 0 { | ||||||
| 			bc.clearItems(keys) | 			bc.clearItems(keys) | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -71,7 +71,9 @@ func (input *BeegoInput) Reset(ctx *Context) { | |||||||
| 	input.CruSession = nil | 	input.CruSession = nil | ||||||
| 	input.pnames = input.pnames[:0] | 	input.pnames = input.pnames[:0] | ||||||
| 	input.pvalues = input.pvalues[:0] | 	input.pvalues = input.pvalues[:0] | ||||||
|  | 	input.dataLock.Lock() | ||||||
| 	input.data = nil | 	input.data = nil | ||||||
|  | 	input.dataLock.Unlock() | ||||||
| 	input.RequestBody = []byte{} | 	input.RequestBody = []byte{} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -74,7 +74,9 @@ func (st *CookieSessionStore) SessionID() string { | |||||||
| 
 | 
 | ||||||
| // SessionRelease Write cookie session to http response cookie | // SessionRelease Write cookie session to http response cookie | ||||||
| func (st *CookieSessionStore) SessionRelease(w http.ResponseWriter) { | func (st *CookieSessionStore) SessionRelease(w http.ResponseWriter) { | ||||||
|  | 	st.lock.Lock() | ||||||
| 	encodedCookie, err := encodeCookie(cookiepder.block, cookiepder.config.SecurityKey, cookiepder.config.SecurityName, st.values) | 	encodedCookie, err := encodeCookie(cookiepder.block, cookiepder.config.SecurityKey, cookiepder.config.SecurityName, st.values) | ||||||
|  | 	st.lock.Unlock() | ||||||
| 	if err == nil { | 	if err == nil { | ||||||
| 		cookie := &http.Cookie{Name: cookiepder.config.CookieName, | 		cookie := &http.Cookie{Name: cookiepder.config.CookieName, | ||||||
| 			Value:    url.QueryEscape(encodedCookie), | 			Value:    url.QueryEscape(encodedCookie), | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user