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

Fix appveyor ci for round3 #2862

Merged
merged 3 commits into from
Mar 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/fluent/plugin_helper/socket_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
module Fluent
module PluginHelper
module SocketOption
# ref: https://docs.microsoft.com/en-us/windows/win32/api/winsock/ns-winsock-linger
FORMAT_STRUCT_LINGER_WINDOWS = 'S!S!' # { u_short l_onoff; u_short l_linger; }
FORMAT_STRUCT_LINGER = 'I!I!' # { int l_onoff; int l_linger; }
FORMAT_STRUCT_TIMEVAL = 'L!L!' # { time_t tv_sec; suseconds_t tv_usec; }

Expand Down Expand Up @@ -49,9 +51,25 @@ def socket_option_set(sock, resolve_name: nil, nonblock: false, linger_timeout:
if nonblock
sock.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
end
if linger_timeout
if Fluent.windows?
# To prevent closing socket forcibly on Windows,
# this options shouldn't be set up when linger_timeout equals to 0 (including nil).
# This unintended behavior always ocurrs on Windows when linger_timeout.to_i == 0.
# This unintented behavior causes "Errno::ECONNRESET: An existing connection was forcibly
# closed by the remote host." on Windows.
if linger_timeout.to_i > 0
if linger_timeout >= 2**16
log.warn "maximum linger_timeout is 65535(2^16 - 1). Set to 65535 forcibly."
linger_timeout = 2**16 - 1
end
optval = [1, linger_timeout.to_i].pack(FORMAT_STRUCT_LINGER_WINDOWS)
cosmo0920 marked this conversation as resolved.
Show resolved Hide resolved
socket_option_set_one(sock, :SO_LINGER, optval)
end
else
if linger_timeout
optval = [1, linger_timeout.to_i].pack(FORMAT_STRUCT_LINGER)
socket_option_set_one(sock, :SO_LINGER, optval)
end
end
if recv_timeout
optval = [recv_timeout.to_i, 0].pack(FORMAT_STRUCT_TIMEVAL)
Expand Down
4 changes: 3 additions & 1 deletion test/plugin/test_buf_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,9 @@ def write_metadata(path, chunk_id, metadata, size, ctime, mtime)
if @bufdir
Dir.glob(File.join(@bufdir, '*')).each do |path|
next if ['.', '..'].include?(File.basename(path))
File.delete(path)
# Windows does not permit to delete files which are used in another process.
# Just ignore for removing failure.
File.delete(path) rescue nil
end
end
end
Expand Down