Guess the language
Jan. 17th, 2019 12:53 pmok, connect to a socket (td-agent here, but it probably doesn't matter):
But what if...
You'd expect the socket to be closed, or eventually error on write?
irb(main):005:0>
irb(main):006:0* sock.write('doh')
=> 3
irb(main):007:0> sock.write('doh')
=> 3
irb(main):008:0> sock.write('doh')
=> 3
irb(main):009:0> sock.write('doh')
=> 3
irb(main):010:0> sock.write('doh')
=> 3
irb(main):011:0>
[1]+ Stopped irb
# netstat -nap | grep 59172
tcp 1 15 127.0.0.1:59172 127.0.0.1:8124 CLOSE_WAIT 12727/irb
But we have 15 bytes (5 * 'doh') queued up instead.
irb(main):023:0* sock = TCPSocket.new('localhost', 8124)
=> #
irb(main):024:0> sock.write('doh')
=> 3
irb(main):025:0>
[1]+ Stopped irb
# service td-agent restart
td-agent stop/waiting
td-agent start/running, process 18296
# fg
irb
irb(main):031:0>
irb(main):032:0* sock.write('doh')
=> 3
irb(main):033:0> sock.write('doh') # yes, we've restarted the server, so connection eventually fails
Errno::EPIPE: Broken pipe
from (irb):33:in `write'
from (irb):33
from /usr/bin/irb:11:in `'
irb(main):034:0> sock.write('doh')
Errno::EPIPE: Broken pipe
from (irb):34:in `write'
from (irb):34
from /usr/bin/irb:11:in `'
But what if...
irb(main):001:0> require 'socket'
=> true
irb(main):002:0> sock = TCPSocket.new('localhost', 8124)
=> #
irb(main):003:0> sock.write('doh')
=> 3
irb(main):004:0>
[1]+ Stopped irb
# service td-agent restart
td-agent stop/waiting
td-agent start/running, process 13180
# fg
irb
sleep 60
sleep 60
=> 60
You'd expect the socket to be closed, or eventually error on write?
irb(main):005:0>
irb(main):006:0* sock.write('doh')
=> 3
irb(main):007:0> sock.write('doh')
=> 3
irb(main):008:0> sock.write('doh')
=> 3
irb(main):009:0> sock.write('doh')
=> 3
irb(main):010:0> sock.write('doh')
=> 3
irb(main):011:0>
[1]+ Stopped irb
# netstat -nap | grep 59172
tcp 1 15 127.0.0.1:59172 127.0.0.1:8124 CLOSE_WAIT 12727/irb
But we have 15 bytes (5 * 'doh') queued up instead.
# fg
irb
^[[A
sock.write('doh')
=> 3
irb(main):012:0> sock.write('doh')
=> 3
irb(main):013:0> sock.write('doh')
=> 3
irb(main):014:0> sock.write('doh')
=> 3
irb(main):015:0> sock.write('doh')
=> 3
irb(main):016:0>
[1]+ Stopped irb
# netstat -nap | grep 59172
tcp 1 30 127.0.0.1:59172 127.0.0.1:8124 CLOSE_WAIT 12727/irb
# fg
irb
^[[A
sock.write('doh')
=> 3
irb(main):017:0> sock.write('doh' * 30000)
=> 90000
irb(main):018:0> sock.write('doh' * 30000)
=> 90000
irb(main):019:0> sock.write('doh' * 30000)
=> 90000
irb(main):020:0> sock.write('doh' * 30000000)
^Z
[1]+ Stopped irb
# netstat -nap | grep 59172
tcp 1 2531843 127.0.0.1:59172 127.0.0.1:8124 CLOSE_WAIT 12727/irb
# fg
irb
^Z
[1]+ Stopped irb
# netstat -nap | grep 59172
tcp 1 2531843 127.0.0.1:59172 127.0.0.1:8124 CLOSE_WAIT 12727/irb
# netstat -nap | grep 59172
tcp 1 2531843 127.0.0.1:59172 127.0.0.1:8124 CLOSE_WAIT 12727/irb
# fg
irb
(...chirp...chirp...)
no subject
Date: 2019-01-17 02:00 pm (UTC)$ alias s='ss -nap | grep 9000 | tr -s " "' $ $ ruby -run -ehttpd . -p9000 & [1] 70344 $ [2019-01-17 15:52:46] INFO WEBrick 1.4.2 [2019-01-17 15:52:46] INFO ruby 2.5.1 (2018-03-29) [x86_64-linux] [2019-01-17 15:52:46] INFO WEBrick::HTTPServer#start: pid=70344 port=9000 $ s tcp LISTEN 0 128 0.0.0.0:9000 0.0.0.0:* users:(("ruby",pid=70344,fd=8)) tcp LISTEN 0 128 [::]:9000 [::]:* users:(("ruby",pid=70344,fd=9)) $ $ irb 2.5.1 :001 > require 'socket' true 2.5.1 :002 > sock = TCPSocket.new 'localhost', 9000 #<TCPSocket:fd 10, AF_INET6, ::1, 36948> 2.5.1 :003 > sock.write 'doh' 3 2.5.1 :004 > [2]+ Stopped irb $ $ s tcp LISTEN 0 128 0.0.0.0:9000 0.0.0.0:* users:(("ruby",pid=70344,fd=8)) tcp LISTEN 0 128 [::]:9000 [::]:* users:(("ruby",pid=70344,fd=9)) tcp ESTAB 0 0 [::1]:36948 [::1]:9000 users:(("ruby",pid=70349,fd=10)) tcp ESTAB 0 0 [::1]:9000 [::1]:36948 users:(("ruby",pid=70344,fd=12)) $ $ kill 70344 [2019-01-17 15:53:55] INFO going to shutdown ... [2019-01-17 15:53:55] INFO WEBrick::HTTPServer#start done. $ [1]- Done ruby -run -ehttpd . -p9000 $ $ s tcp CLOSE-WAIT 1 0 [::1]:36948 [::1]:9000 users:(("ruby",pid=70349,fd=10)) tcp FIN-WAIT-2 0 0 [::1]:9000 [::1]:36948 $ $ ruby -run -ehttpd . -p9000 & [3] 70363 $ [2019-01-17 15:54:14] INFO WEBrick 1.4.2 [2019-01-17 15:54:14] INFO ruby 2.5.1 (2018-03-29) [x86_64-linux] [2019-01-17 15:54:14] INFO WEBrick::HTTPServer#start: pid=70363 port=9000 $ s tcp LISTEN 0 128 0.0.0.0:9000 0.0.0.0:* users:(("ruby",pid=70363,fd=8)) tcp LISTEN 0 128 [::]:9000 [::]:* users:(("ruby",pid=70363,fd=9)) tcp CLOSE-WAIT 1 0 [::1]:36948 [::1]:9000 users:(("ruby",pid=70349,fd=10)) tcp FIN-WAIT-2 0 0 [::1]:9000 [::1]:36948 $ $ fg irb sleep 60 sleep 60 60 2.5.1 :005 > sock.write 'doh' 3 2.5.1 :006 > sock.write 'doh' Traceback (most recent call last): 3: from /home/alex/.rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>' 2: from (irb):6 1: from (irb):6:in `write' Errno::EPIPE (Broken pipe) 2.5.1 :007 > $ s tcp LISTEN 0 128 0.0.0.0:9000 0.0.0.0:* users:(("ruby",pid=70363,fd=8)) tcp LISTEN 0 128 [::]:9000 [::]:* users:(("ruby",pid=70363,fd=9))no subject
Date: 2019-01-17 02:40 pm (UTC)no subject
Date: 2019-01-22 07:00 am (UTC)до речі,
(особливо правий стовпець)
та https://www.ruby-lang.org/en/security/
I'm just sayin'
no subject
Date: 2019-01-22 07:46 am (UTC)no subject
Date: 2019-01-21 03:27 pm (UTC)Бо я навчився отримувати таку ж помилку і в пітоні
no subject
Date: 2019-01-21 03:37 pm (UTC)no subject
Date: 2019-01-21 05:22 pm (UTC)-A INPUT -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j DROP
-A INPUT -i lo -j ACCEPT
- отак висить
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j DROP
- отак працює
ну, і, звичайно, echo 120 > /proc/sys/net/netfilter/nf_conntrack_tcp_timeout_close_wait теж працює (тобто, тоді починає висіти через 120 секунд, а не 60)
no subject
Date: 2019-01-22 06:38 am (UTC)хех
а це цікаво, дякую!