Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve 'A thread timer expired 5.xxxxxx seconds ago' issue #2475

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/man/man5/keepalived.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -1715,14 +1715,14 @@ The syntax for vrrp_instance is :
}

# add a tracking script to the interface
# (<SCRIPT_NAME> is the name of the vrrp_track_script entry)
# (<SCRIPT_NAME> is the name of the vrrp_script entry)
# The same principle as track_interface can be applied to track_script entries,
# except that an unspecified weight means that the default weight declared in
# the script will be used (which itself defaults to 0).
# reverse causes the direction of the adjustment of the priority to be reversed.
\fBtrack_script \fR{
<SCRIPT_NAME>
<SCRIPT_NAME> weight <-253..253> [reverse|no_reverse]
<SCRIPT_NAME> weight <-253..253> [reverse|noreverse]
}

# Files whose state we monitor, value is added to effective priority.
Expand Down
9 changes: 0 additions & 9 deletions keepalived/core/layer4.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ socket_bind_connect(int fd, conn_opts_t *co)
{
int opt;
socklen_t optlen;
struct linger li;
socklen_t addrlen;
int ret;
const sockaddr_t *addr = &co->dst;
Expand All @@ -95,14 +94,6 @@ socket_bind_connect(int fd, conn_opts_t *co)
log_message(LOG_ERR, "Can't get socket type: %s", strerror(errno));
return connect_error;
}
if (opt == SOCK_STREAM) {
/* free the tcp port after closing the socket descriptor, but
* allow time for a proper shutdown. */
li.l_onoff = 1;
li.l_linger = 5;
if (setsockopt(fd, SOL_SOCKET, SO_LINGER, PTR_CAST(char, &li), sizeof (struct linger)))
log_message(LOG_INFO, "Failed to set SO_LINGER for socket %d - errno %d (%m)", fd, errno);
}

#ifdef _WITH_SO_MARK_
if (co->fwmark) {
Expand Down
8 changes: 8 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CFLAGS = -O2 -g

all: tcp_server tcp_client

tcp_server: tcp_server.c

tcp_client: tcp_client.c
gcc -o tcp_client tcp_client.c -lreadline
27 changes: 23 additions & 4 deletions test/tcp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <readline/readline.h>
#include <readline/history.h>
#include <string.h>
#include <fcntl.h>

static void
print_usage(FILE *fp, const char *name)
Expand All @@ -21,6 +22,7 @@ print_usage(FILE *fp, const char *name)
fprintf(fp, "\t-d dly\t\tdelay dly seconds after connect\n");
fprintf(fp, "\t-e\t\tsend stdin\n");
fprintf(fp, "\t-f\t\tenable tcp_fastopen\n");
fprintf(fp, "\t-S\t\tdon't sleep after socket close\n");
fprintf(fp, "\t-h\t\tprint this\n");
}

Expand Down Expand Up @@ -58,9 +60,10 @@ int main(int argc, char **argv)
char *msg = malloc(msglen);
uint8_t *buf = malloc(msglen);
unsigned delay_after_connect = 0;
bool do_sleep = true;
int flags;


while ((opt = getopt(argc, argv, ":ha:p:sud:ef")) != -1) {
while ((opt = getopt(argc, argv, ":ha:p:sSud:ef")) != -1) {
switch (opt) {
case 'a':
addr_str = optarg;
Expand Down Expand Up @@ -94,6 +97,9 @@ int main(int argc, char **argv)
case 'f':
tcp_fastopen = true;
break;
case 'S':
do_sleep = false;
break;
case ':':
fprintf(stderr, "Option '%c' is missing an argument\n", optopt);
break;
Expand Down Expand Up @@ -150,11 +156,24 @@ int main(int argc, char **argv)
}

shutdown(sock, SHUT_WR);

if ((flags = fcntl(sock, F_GETFL, 0)) < 0)
printf("fcntl get failed - %m\n");
else if (fcntl(sock, F_SETFL, flags | SOCK_NONBLOCK) < 0)
printf("fcntl set failed - %m\n");

len = read(sock, buf, msglen - 1);
printf("Final read returned %d\n", len);
if (len < 0)
printf("Final read returned errno %d - %m\n", errno);
else
printf("Final read returned %d\n", len);

shutdown(sock, SHUT_RD);

close(sock);
sleep(1);

if (do_sleep)
sleep(1);

freeaddrinfo(res);
}
28 changes: 23 additions & 5 deletions test/tcp_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ print_usage(FILE *fp, const char *name)
fprintf(fp, "\t-v ver\t\tset HTML version to use (default 1.1)\n");
fprintf(fp, "\t-w url resp\tsend HTTP response for url\n");
fprintf(fp, "\t-W\t\tsend a pre-build HTTP response for GET /\n");
fprintf(fp, "\t-x url\t\tsend a pre-build HTTP response for url /\n");
fprintf(fp, "\t-M[server_name]\tbe an email server\n");
fprintf(fp, "\t-l val\t\tASCII value to use for EOL char\n");
fprintf(fp, "\t-d delay\tdelay in ms before replying\n");
Expand Down Expand Up @@ -326,8 +327,10 @@ int main(int argc, char **argv)
unsigned immediate_data_len;
char *immediate_data = NULL;
bool immediate_data_malloc = false;
char client_addr_buf[40];
unsigned client_port;

while ((opt = getopt(argc, argv, ":h46a:p:suPeb:c:l:d:rm:v:WM::w:ZDgGi:S"
while ((opt = getopt(argc, argv, ":h46a:p:suPeb:c:l:d:rm:v:WM::w:x:ZDgGi:S"
#ifdef TCP_FASTOPEN
"f:"
#endif
Expand Down Expand Up @@ -399,6 +402,14 @@ int main(int argc, char **argv)

new_html_cr(optarg, argv[optind++], html_version, close_after_send);
break;
case 'x':
if (optind >= argc + 1) {
fprintf(stderr, "-%c '%s' missing response\n", optind, optarg);
exit(EXIT_FAILURE);
}

new_html_cr(optarg, html_resp, html_version, close_after_send);
break;
case 'l':
EOL = strtoul(optarg, &endptr, 10);
break;
Expand Down Expand Up @@ -538,14 +549,17 @@ int main(int argc, char **argv)
if (family == AF_INET) {
clilen = sizeof (cliaddr);
connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &clilen);
}
else {
client_port = ntohs(cliaddr.sin_port);
inet_ntop(AF_INET, &cliaddr.sin_addr, client_addr_buf, sizeof(client_addr_buf));
} else {
clilen = sizeof (cliaddr6);
connfd = accept(listenfd, (struct sockaddr *)&cliaddr6, &clilen);
client_port = ntohs(cliaddr6.sin6_port);
inet_ntop(AF_INET6, &cliaddr6.sin6_addr, client_addr_buf, sizeof(client_addr_buf));
}

if (!silent && (!(++connection_num % connection_mod) || connection_num == 1))
printf("(%d) Received connection %lu\n", getpid(), connection_num);
printf("(%d) Received connection %lu from %s:%u\n", getpid(), connection_num, client_addr_buf, client_port);
if ((childpid = fork()) == 0) {
close(listenfd);

Expand All @@ -566,17 +580,21 @@ int main(int argc, char **argv)
if (family == AF_INET) {
clilen = sizeof (cliaddr);
n = recvfrom(listenfd, buf, sizeof(buf), 0, (struct sockaddr *)&cliaddr, &clilen);
client_port = ntohs(cliaddr.sin_port);
inet_ntop(AF_INET, &cliaddr.sin_addr, client_addr_buf, sizeof(client_addr_buf));
if (echo_data)
sendto(listenfd, buf, n, 0, (struct sockaddr *)&cliaddr, clilen);
}
else {
clilen = sizeof (cliaddr6);
n = recvfrom(listenfd, buf, sizeof(buf), 0, (struct sockaddr *)&cliaddr6, &clilen);
client_port = ntohs(cliaddr6.sin6_port);
inet_ntop(AF_INET, &cliaddr6.sin6_addr, client_addr_buf, sizeof(client_addr_buf));
if (echo_data)
sendto(listenfd, buf, n, 0, (struct sockaddr *)&cliaddr6, clilen);
}
if (!silent)
printf("(%d) Received %d bytes\n", getpid(), n);
printf("(%d) Received %d bytes from %s:%u\n", getpid(), n, client_addr_buf, client_port);
}
} else {
/* SOCK_RAW => stdin/out */
Expand Down
Loading