1. 程式人生 > >ab測試出現error: connection reset by peer的解決方案

ab測試出現error: connection reset by peer的解決方案

我們在使用一些開源程式之前,可能會使用ab工具在伺服器或者本地進行一次效能評估,但是很多時候卻總是會以失敗告終,因為,伺服器會拒絕你的ab工具發出的http請求, 出現 error: connection reset by peer, 這該怎麼辦呢?

首先,為了測試一個具有sql操作的頁面,通常需要登入,這時候需要偽裝成一個使用者來實現自動登入,簡單的方法就是:在瀏覽器端登入一個使用者,開啟chrome的developer tool,將其中的cookie複製,用-H option來實現帶cookie的http請求,其餘的併發任務交給ab工具,使得每個http都攜帶session對應的cookie,如果這樣就ok了,基本上說明這個web app安全性有待考量,這也是初級使用者可能忽略的問題。

其次,如果偽裝成登入使用者,攜帶了cookie依然出現這個錯誤,那麼通常是由於web app原始碼中開啟了csrf防護,針對偽裝的請求做了過濾,這個問題也相對好解決,因為是開放原始碼,我們可以開啟原始碼,找到這個web app的框架級的config檔案,或者是 application級別的啟動器類,就可以方便快速地找到這段程式,將csrf防護關閉就可以了。以下就以rails應用, 和  sails.js應用為例,講述如何關閉csrf防護。

rails應用:程式碼在controller目錄下的ApplicationController.rb檔案,將其中的csrf保護函式protect_from_forgery中cookie.delete(auto_cookie_name)行註釋掉。或者將protect_from_forgery註釋掉,程式碼如下:

 
class ApplicationController < ActionController::Base
  include Redmine::I18n
  include Redmine::Pagination
  include RoutesHelper
  helper :routes
 
  class_attribute :accept_api_auth_actions
  class_attribute :accept_rss_auth_actions
  class_attribute :model_object
 
  layout 'base
' protect_from_forgery def handle_unverified_request super #cookies.delete(autologin_cookie_name) end before_filter :session_expiration, :user_setup, :check_if_login_required, :set_localization rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token rescue_from ::Unauthorized, :with => :deny_access rescue_from ::ActionView::MissingTemplate, :with => :missing_template include Redmine::Search::Controller include Redmine::MenuManager::MenuController helper Redmine::MenuManager::MenuHelper def session_expiration if session[:user_id] if session_expired? && !try_to_autologin reset_session flash[:error] = l(:error_session_expired) redirect_to signin_url else #session[:atime] = Time.now.utc.to_i end end end

如果是sails.js web app, 那麼就更加簡單了,開啟config目錄下,有一個csrf檔案,將csrf設定為false就可以了。

在關閉了csrf之後,基本上ab測試就不會再出現error: connection reset by peer 了。

如果你對手頭沒有原始碼的web app的效能測試感興趣,可以參考我的其它文章。

參考:

檢查丟包利器dropwatch: http://blog.yufeng.info/archives/2497

ulimit問題及其影響: http://blog.yufeng.info/archives/1380

相關推薦

ab測試出現error: connection reset by peer解決方案

我們在使用一些開源程式之前,可能會使用ab工具在伺服器或者本地進行一次效能評估,但是很多時候卻總是會以失敗告終,因為,伺服器會拒絕你的ab工具發出的http請求, 出現 error: connection reset by peer, 這該怎麼辦呢? 首先,為了測試一個具有sql操作的頁面,通常需要登入,這

Redis連接出現Error: Connection reset by peer的問題是由於使用Redis的安全模式

現在網上一查出現安全模式的連線,基本都是要關閉服務端的操作,其實這種方式是不正確的,最有效的解決方式是使用stunnel進行安全模式的連線。 我碰到的問題是微軟雲(其實我不想用!)連線Redis,預設採用6380做為SSL埠,而微軟雲同時還會啟用非SSL埠6379,如果嫌其麻煩,可以用非SSL進行連線。

Android Studio 出現Error:Connection timed out: connect.解決方案

錯誤發生在構建Gradle的過程中正在下載gradle.zip檔案的時候 這個時候檢查下開啟專案裡gradle\wrapper\gradle-wrapper.properties這個檔案的gradle

下載標準庫libcxx出現svn: E000104: Error running context: Connection reset by peer解決方案

使用svn co http://llvm.org/svn/llvm-project/libcxx/tags/RELEASE_500/final libcxx下載標準庫libcxx出現svn: E000104: Error running context: Connection reset b

java使用axis呼叫webservice時出現Connection reset by peer: socket write error的一種解決方法

call.addParameter( new QName(nameSpace,"excelContent"), org.apache.axis.encoding.XMLType.SOAP_BASE64BINARY, javax.xml.rpc.ParameterMode.I

pyspider連線rabbitmq ,結果出現socket.error: [Errno 104] Connection reset by peer 這樣的報錯資訊

linux系統中: pyspider+rabbitmq+mongodb環境下啟動pyspider時出現socket.error: [Errno 104] Connection reset by peer 的錯誤資訊。 首先,分享一下自己總結的做維護或者排除bug 的思路:

connection reset by peer, socket write error問題分析

getc 主動 連接 返回 知識 可能 -- 成功 connect 上次寫《connection reset by peer, socket write error問題排查》已經過去大半年,當時把問題“敷衍”過去了。 但是此後每隔一段時間就會又想起來,baidu、googl

docker exec failed!!error from pipe caused \"read parent: connection reset by peer\"問題

一、復現報錯: docker exec -it  wsqtest  bash rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container p

SSH error ( Read from socket failed: Connection reset by peer ) and it's solution

ssh cann't connected ,event in localhost[[email protected] ssh]# ssh 127.0.0.1Read from socket failed: Connection reset by peertry the following refe

Connection reset by peer: socket write error錯誤分析及解決

Connection reset by peer: socket write error錯誤分析:常出現的Connection reset by peer: 原因可能是多方面的,不過更常見的原因是:  ①:伺服器的併發連線數超過了其承載量,伺服器會將其中一些連線Down掉; 

vmware虛擬機器下CentOS7.2出現ssh連線被connection reset by peer錯誤

用vmware 11 安裝了centos7.2後,用ssh工具遠端連接出現connection reset by peer錯誤,檢查防火牆和/etc/hosts.deny等都沒有發現問題,於是停止sshd服務,啟用debug模式跟蹤: /usr/sbin/sshd -d 

Nginx error code 54: Connection reset by peer

Nginx 54: Connection reset by peer 2018/05/28 17:12:42 [error] 19745#0: *76 kevent() reported that upstream closed connection (5

nginx [error] 15644#0: *112680 recv() failed (104: Connection reset by peer) while reading response

參考地址   https://serverfault.com/questions/543999/nginx-errors-recv-failed-104-connection-reset-by-peer-while-reading-respon/544106 網站登入的時候

【OpenStack】SSH登入虛擬機器出現"Read from socket failed: Connection reset by peer"問題的解決辦法

宣告: 本部落格歡迎轉發,但請保留原作者資訊! 新浪微博:@孔令賢HW; 內容系本人學習、研究和總結,如有雷同,實屬榮幸! 1、問題現象 版本:Grizzly master分支程式碼2013.06.17 部署:三個節點(Controller/Compute + Netw

FtpClient連線ftp 報Connection reset by peer: socket write error異常

使用FtpClient連線ftp時候發現報Connection reset by peer: socket write error錯誤,但是之前一個demo連線確沒有問題,最後對比了一下發現jdk版本不一樣,報錯專案使

LR回放https協議腳本失敗:[GENERAL_MSG_CAT_SSL_ERROR]connect to host "XXX" failed:[10054] Connection reset by peer [MsgId:MERR-27780]

網絡連接 advance sgid 服務器 vuser con run load sgi 最近做一個負載均衡項目的性能測試,使用LR錄制腳本協議為https協議,回放腳本時出現報錯: [GENERAL_MSG_CAT_SSL_ERROR]connect to host "

CentOS7使用ssh不能登錄,報錯:Read from socket failed: Connection reset by peer

read from socket failed: connection reset by peer使用xshell登錄CentOS7,不能登錄,使用另外一臺Linux主機,telent 22端口是同的,ssh連接報以下錯誤:Read from socket failed: Connection reset b

ECS雲主機SSH連接提示“Connection reset by peer”的解決辦法和解決思路

阿裏雲 運維思想 工單支持 三周前剛從上家公司換到新的公司,這家公司與上家公司相比對阿裏雲的雲計算環境更加的依賴,使用的ECS實例和其他服務如SLB、RDS、OSS等更多了一個數量級。這篇文章的背景就是為了解決阿裏雲ECS雲主機SSH連接的一個問題,從故障發現到故障排除到最後反思的一個詳細

CentOS7 yum的一次報錯" 14: curl#56 - "Recv failure: Connection reset by peer" "

yum1、故障現象[[email protected]/* */ src]# yum update Loaded plugins: fastestmirror, langpacks Could not retrieve mirrorlist 7&arch=x86_64&repo

connection reset by peer問題總結及解決方案

net 方維 catch 火墻 tst buffer 整理 pos 在服務器 找遍了 中英文網站,翻遍了能找的角落,發現了出現故障的原因和原理,及改如何處理,這裏記錄下,希望能幫助到有需要的小夥伴,少走點彎路, 以上就整理內容: connection res