Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(173)

Side by Side Diff: session.go

Issue 8367044: mgo: fix possible race
Patch Set: mgo: fix possible race Created 12 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « [revision details] ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // mgo - MongoDB driver for Go 1 // mgo - MongoDB driver for Go
2 //· 2 //·
3 // Copyright (c) 2010-2012 - Gustavo Niemeyer <gustavo@niemeyer.net> 3 // Copyright (c) 2010-2012 - Gustavo Niemeyer <gustavo@niemeyer.net>
4 //· 4 //·
5 // All rights reserved. 5 // All rights reserved.
6 // 6 //
7 // Redistribution and use in source and binary forms, with or without 7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:· 8 // modification, are permitted provided that the following conditions are met:·
9 //· 9 //·
10 // 1. Redistributions of source code must retain the above copyright notice, thi s 10 // 1. Redistributions of source code must retain the above copyright notice, thi s
(...skipping 2876 matching lines...) Expand 10 before | Expand all | Expand 10 after
2887 } 2887 }
2888 2888
2889 // --------------------------------------------------------------------------- 2889 // ---------------------------------------------------------------------------
2890 // Internal session handling helpers. 2890 // Internal session handling helpers.
2891 2891
2892 func (s *Session) acquireSocket(slaveOk bool) (*mongoSocket, error) { 2892 func (s *Session) acquireSocket(slaveOk bool) (*mongoSocket, error) {
2893 2893
2894 // Read-only lock to check for previously reserved socket. 2894 // Read-only lock to check for previously reserved socket.
2895 s.m.RLock() 2895 s.m.RLock()
2896 if s.masterSocket != nil { 2896 if s.masterSocket != nil {
2897 sock := s.masterSocket
2898 sock.Acquire()
2897 s.m.RUnlock() 2899 s.m.RUnlock()
2898 » » s.masterSocket.Acquire() 2900 » » return sock, nil
2899 » » return s.masterSocket, nil
2900 } 2901 }
2901 if s.slaveSocket != nil && s.slaveOk && slaveOk { 2902 if s.slaveSocket != nil && s.slaveOk && slaveOk {
2903 sock := s.slaveSocket
2904 sock.Acquire()
2902 s.m.RUnlock() 2905 s.m.RUnlock()
2903 » » s.slaveSocket.Acquire() 2906 » » return sock, nil
2904 » » return s.slaveSocket, nil
2905 } 2907 }
2906 s.m.RUnlock() 2908 s.m.RUnlock()
2907 2909
2908 // No go. We may have to request a new socket and change the session, 2910 // No go. We may have to request a new socket and change the session,
2909 // so try again but with an exclusive lock now. 2911 // so try again but with an exclusive lock now.
2910 s.m.Lock() 2912 s.m.Lock()
2911 defer s.m.Unlock() 2913 defer s.m.Unlock()
2912 2914
2913 if s.masterSocket != nil { 2915 if s.masterSocket != nil {
2914 s.masterSocket.Acquire() 2916 s.masterSocket.Acquire()
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3066 } 3068 }
3067 panic("unreachable") 3069 panic("unreachable")
3068 } 3070 }
3069 3071
3070 func hasErrMsg(d []byte) bool { 3072 func hasErrMsg(d []byte) bool {
3071 return len(d) > 16 && 3073 return len(d) > 16 &&
3072 d[5] == 'e' && d[6] == 'r' && d[7] == 'r' && 3074 d[5] == 'e' && d[6] == 'r' && d[7] == 'r' &&
3073 d[8] == 'm' && d[9] == 's' && d[10] == 'g' && 3075 d[8] == 'm' && d[9] == 's' && d[10] == 'g' &&
3074 d[11] == '\x00' && d[4] == '\x02' 3076 d[11] == '\x00' && d[4] == '\x02'
3075 } 3077 }
OLDNEW
« no previous file with comments | « [revision details] ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b