sonic-swss icon indicating copy to clipboard operation
sonic-swss copied to clipboard

[mclagsyncd] fix out of order initialization

Open bratashX opened this issue 3 years ago • 2 comments

It's cherry-pick from master branch: https://github.com/Azure/sonic-swss/pull/2112

What I did

Reorder class member variables.

Why I did it

I've encountered an issue with m_bufSize, it's initialization is random, some times it may be initializied with 0, some times with random value.

m_bufSize use MSG_BATCH_SIZE for initialization:

MclagLink::MclagLink(Select *select, int port) :
    MSG_BATCH_SIZE(256),
    m_bufSize(MCLAG_MAX_MSG_LEN * MSG_BATCH_SIZE),
    ...

but MSG_BATCH_SIZE declared after m_bufSize


class MclagLink : public Selectable {
  private:
    unsigned int m_bufSize;
    ...
    const int MSG_BATCH_SIZE;
    ...

so MSG_BATCH_SIZE will be initialized after m_bufSize, and m_bufSize will use MSG_BATCH_SIZE with uninitialized value.

How I verified it

Setup mclag topology, some times mclagsyncd will not be able to receive data after startup.

Details if related

More about this issue in cpp reference

IMHO it must be treated as compilation error, so it will be better to use-Werror=reorder parameter for compiler to avoid such issues.

Signed-off-by: Petro Bratash [email protected]

bratashX avatar May 13 '22 23:05 bratashX

/easycla

bratashX avatar Aug 09 '22 07:08 bratashX

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: bratashX / name: Petro Bratash (7d572170e83146af42bd07f35f8a17ad44f137e6)