Remove pid-caching from BufferPoolAccessor

BufferPoolAccessor cached the pid via a static constructor. If the
process forks after this, then multiple processes generating unique ids
using the same pid value. This resulted in connection ID collisions.
use getpid(), which  already caches and resets appropriately across fork().

Bug: 142423602
Bug: 133186424
Test: boot, watch log connectionIds, collision-induced failures are gone
gugelfrei
Ray Essick 5 years ago
parent 5871ab5121
commit 3688d0aa11

@ -14,10 +14,11 @@
* limitations under the License.
*/
#define LOG_TAG "BufferPoolAccessor"
#define LOG_TAG "BufferPoolAccessor1.0"
//#define LOG_NDEBUG 0
#include <sys/types.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#include <utils/Log.h>
@ -127,7 +128,6 @@ bool contains(std::map<T, std::set<U>> *mapOfSet, T key, U value) {
return false;
}
int32_t Accessor::Impl::sPid = getpid();
uint32_t Accessor::Impl::sSeqId = time(nullptr);
Accessor::Impl::Impl(
@ -145,14 +145,19 @@ ResultStatus Accessor::Impl::connect(
{
std::lock_guard<std::mutex> lock(mBufferPool.mMutex);
if (newConnection) {
ConnectionId id = (int64_t)sPid << 32 | sSeqId;
int32_t pid = getpid();
ConnectionId id = (int64_t)pid << 32 | sSeqId;
status = mBufferPool.mObserver.open(id, fmqDescPtr);
if (status == ResultStatus::OK) {
newConnection->initialize(accessor, id);
*connection = newConnection;
*pConnectionId = id;
mBufferPool.mConnectionIds.insert(id);
++sSeqId;
if (sSeqId == UINT32_MAX) {
sSeqId = 0;
} else {
++sSeqId;
}
}
}
mBufferPool.processStatusMessages();

@ -61,7 +61,6 @@ private:
// ConnectionId = pid : (timestamp_created + seqId)
// in order to guarantee uniqueness for each connection
static uint32_t sSeqId;
static int32_t sPid;
const std::shared_ptr<BufferPoolAllocator> mAllocator;

@ -14,10 +14,11 @@
* limitations under the License.
*/
#define LOG_TAG "BufferPoolAccessor"
#define LOG_TAG "BufferPoolAccessor2.0"
//#define LOG_NDEBUG 0
#include <sys/types.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#include <utils/Log.h>
@ -134,7 +135,6 @@ bool contains(std::map<T, std::set<U>> *mapOfSet, T key, U value) {
return false;
}
int32_t Accessor::Impl::sPid = getpid();
uint32_t Accessor::Impl::sSeqId = time(nullptr);
Accessor::Impl::Impl(
@ -156,7 +156,8 @@ ResultStatus Accessor::Impl::connect(
{
std::lock_guard<std::mutex> lock(mBufferPool.mMutex);
if (newConnection) {
ConnectionId id = (int64_t)sPid << 32 | sSeqId;
int32_t pid = getpid();
ConnectionId id = (int64_t)pid << 32 | sSeqId;
status = mBufferPool.mObserver.open(id, statusDescPtr);
if (status == ResultStatus::OK) {
newConnection->initialize(accessor, id);
@ -166,7 +167,11 @@ ResultStatus Accessor::Impl::connect(
mBufferPool.mConnectionIds.insert(id);
mBufferPool.mInvalidationChannel.getDesc(invDescPtr);
mBufferPool.mInvalidation.onConnect(id, observer);
++sSeqId;
if (sSeqId == UINT32_MAX) {
sSeqId = 0;
} else {
++sSeqId;
}
}
}

@ -75,7 +75,6 @@ private:
// ConnectionId = pid : (timestamp_created + seqId)
// in order to guarantee uniqueness for each connection
static uint32_t sSeqId;
static int32_t sPid;
const std::shared_ptr<BufferPoolAllocator> mAllocator;

Loading…
Cancel
Save