|
12 | 12 | #include "warm_restart.h"
|
13 | 13 | #include "teamsync.h"
|
14 | 14 |
|
| 15 | +#include <unistd.h> |
| 16 | + |
15 | 17 | using namespace std;
|
16 | 18 | using namespace std::chrono;
|
17 | 19 | using namespace swss;
|
@@ -203,32 +205,54 @@ TeamSync::TeamPortSync::TeamPortSync(const string &lagName, int ifindex,
|
203 | 205 | m_lagName(lagName),
|
204 | 206 | m_ifindex(ifindex)
|
205 | 207 | {
|
206 |
| - m_team = team_alloc(); |
207 |
| - if (!m_team) |
208 |
| - { |
209 |
| - SWSS_LOG_ERROR("Unable to allocated team socket"); |
210 |
| - throw system_error(make_error_code(errc::address_not_available), |
211 |
| - "Unable to allocated team socket"); |
212 |
| - } |
213 |
| - |
214 |
| - int err = team_init(m_team, ifindex); |
215 |
| - if (err) |
216 |
| - { |
217 |
| - team_free(m_team); |
218 |
| - m_team = NULL; |
219 |
| - SWSS_LOG_ERROR("Unable to init team socket"); |
220 |
| - throw system_error(make_error_code(errc::address_not_available), |
221 |
| - "Unable to init team socket"); |
222 |
| - } |
| 208 | + int count = 0; |
| 209 | + int max_retries = 3; |
223 | 210 |
|
224 |
| - err = team_change_handler_register(m_team, &gPortChangeHandler, this); |
225 |
| - if (err) |
| 211 | + while (true) |
226 | 212 | {
|
227 |
| - team_free(m_team); |
228 |
| - m_team = NULL; |
229 |
| - SWSS_LOG_ERROR("Unable to register port change event"); |
230 |
| - throw system_error(make_error_code(errc::address_not_available), |
231 |
| - "Unable to register port change event"); |
| 213 | + try |
| 214 | + { |
| 215 | + m_team = team_alloc(); |
| 216 | + if (!m_team) |
| 217 | + { |
| 218 | + throw system_error(make_error_code(errc::address_not_available), |
| 219 | + "Unable to allocate team socket"); |
| 220 | + } |
| 221 | + |
| 222 | + int err = team_init(m_team, ifindex); |
| 223 | + if (err) |
| 224 | + { |
| 225 | + team_free(m_team); |
| 226 | + m_team = NULL; |
| 227 | + throw system_error(make_error_code(errc::address_not_available), |
| 228 | + "Unable to initialize team socket"); |
| 229 | + } |
| 230 | + |
| 231 | + err = team_change_handler_register(m_team, &gPortChangeHandler, this); |
| 232 | + if (err) |
| 233 | + { |
| 234 | + team_free(m_team); |
| 235 | + m_team = NULL; |
| 236 | + throw system_error(make_error_code(errc::address_not_available), |
| 237 | + "Unable to register port change event"); |
| 238 | + } |
| 239 | + |
| 240 | + break; |
| 241 | + } |
| 242 | + catch (const system_error& e) |
| 243 | + { |
| 244 | + if (++count == max_retries) |
| 245 | + { |
| 246 | + throw; |
| 247 | + } |
| 248 | + else |
| 249 | + { |
| 250 | + SWSS_LOG_WARN("Failed to initialize team handler. LAG=%s error=%d:%s, attempt=%d", |
| 251 | + lagName.c_str(), e.code().value(), e.what(), count); |
| 252 | + } |
| 253 | + |
| 254 | + sleep(1); |
| 255 | + } |
232 | 256 | }
|
233 | 257 |
|
234 | 258 | /* Sync LAG at first */
|
|
0 commit comments