2016-04-01 19 views
11

Chúng tôi đang gặp sự cố với signalR. Chúng tôi có trang web đấu giá chạy trên signalr cho đặt giá thầu thời gian thực. Chúng tôi đã khắc phục một số sự cố với trình duyệt và mọi thứ dường như hoạt động tốt. Sau đó, chúng tôi cài đặt di tích mới trên máy chủ của chúng tôi và nhận thấy rằng mỗi phút chúng tôi nhận được mã lỗi http 400 trên signalr kết nối, kết nối lại và hủy bỏ. Dưới đây là một ảnh chụp màn hình:SignalR gây ra yêu cầu xấu 400 được thấy trên máy chủ

New Relic Data

SignalR kết nối và kết nối lại là những hoạt động của trang web tiêu thụ theo khu di tích mới thời gian nhất.

Đây là SignalR đang backend (Chúng tôi sử dụng máy chủ sql như signalr backplane):

public class SignalRHub : Hub 
{ 
    public void BroadCastMessage(String msg) 
    { 
     var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>(); 

     hubContext.Clients.All.receiveMessage(msg); 
    } 
} 

public partial class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     string appString=string.Empty; 

     //Gets the connection string. 
     if (System.Configuration.ConfigurationSettings.AppSettings["SignaRScaleoutConn"] != null) 
     { 
      appString = System.Configuration.ConfigurationSettings.AppSettings["SignaRScaleoutConn"].ToString(); 
     } 

     GlobalHost.DependencyResolver.UseSqlServer(appString); 
     GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromMinutes(15); //I added this timeout, but it is not required. 
     app.MapSignalR(); 
    } 
} 

Client javascript trông như thế này, thật dài, nhưng hầu hết trong số đó là jQuery để ảnh hưởng đến DOM, tôi cho nó tất cả trong trường hợp một cái gì đó có thể sai bên trong nó.

$(function() { 

      var chatProxy = $.connection.signalRHub; 

      $.connection.hub.start(); 

      chatProxy.client.receiveMessage = function (msg) { 

       var all = $(".soon").map(function() { 

        var hiddenModelId = $("#hiddenListingId"); 

        if (msg == hiddenModelId.val()) { 

         $.ajax({ 
          async: "true", 
          url: "/Listing/AuctionRemainingTime", 
          type: "POST", 
          dataType: 'json', 
          data: '{ "listingID": "' + msg + '"}', 
          contentType: "application/json; charset=utf-8", 
          success: function (data) { 
           if (data != null) { 

            SoonSettings.HasReloadedThisTick = false; 

            var element = document.getElementById(msg); 

            var obj = JSON.parse(data) 

            // For Clock Counter End Date Time Interval 
            // Adds 2 minutes to the soon clock when bid is close to finishing. 
            var hdID = "hdn" + obj.ListingId; 
            var hdValue = $("#" + hdID); 
            if (obj.EndDate != hdValue.val()) { 

             SoonSettings.HasUpdated = false; //Allows clock to change color once it gets under two minutes. 

             $('#' + hdID).val(obj.EndDate); 
             Soon.destroy(element); 
             Soon.create(element, { //Recreates clock with the before 2 minute tick event. 
              'due': 'in ' + obj.Seconds + ' seconds', 
              'layout':'group label-uppercase', 
              'visual':'ring cap-round progressgradient-00fff6_075fff ring-width-custom gap-0', 
              'face':'text', 
              'eventTick': 'tick' 
             }); 
            } 

            var highbid = obj.HighBidderURL; 

            // For Date Ends Info. 
            var ListingEndDate = $("#tdAuctionListingEndDate"); 

            if (obj.EndDate != ListingEndDate.val()) { 
             $('#' + hdID).val(obj.EndDate); 
             ListingEndDate.text(obj.EndDate + " Eastern"); 
             ListingEndDate.effect("pulsate", { times: 5 }, 5000); 
            } 
            else 
            { 
             $(".Bidding_Current_Price").stop(true, true); ///Removes the pulsating effect. 
             $(".Bidding_Current_Price").removeAttr("style"); //Removes unnecessary attribute from HTML. 
            } 

            //Bid div notification. 
            if (obj.AcceptedActionCount.replace(/[^:]+:*/, "") > 0) { 

             if (obj.Disposition != '' && obj.Disposition != null) { 
              if (obj.Disposition == "Neutral") { 
               $("#spanNeutralBid").show(); 
               $("#divOutbidNotification").hide(); 
               $("#spanPositiveBid").hide(); 
               $("#divProxyBidNotification").hide(); 
              } 
              else if (obj.Disposition == "Positive") { 
               $("#spanPositiveBid").show(); 
               $("#divOutbidNotification").hide(); 
               $("#spanNeutralBid").hide(); 
               $("#divProxyBidNotification").hide(); 
              } 
              else if (obj.Disposition == "Negative") { 
               $("#divOutbidNotification").show(); 
               $("#spanNeutralBid").hide(); 
               $("#spanPositiveBid").hide(); 
               $("#divProxyBidNotification").hide(); 
              } 
              else { 
               $("#divOutbidNotification").hide(); 
               $("#spanNeutralBid").hide(); 
               $("#divProxyBidNotification").hide(); 
               $("#spanPositiveBid").hide();  
              } 

             } 
            } 

            // For Highlight Current Price when it is Updated 
            var hdCurrentPrice = $("#hdnCurrentPrice"); 

            if (obj.CurrentPrice != hdCurrentPrice.val()) { 

             $(".Bidding_Current_Price").text(obj.CurrentPrice); 
             $(".Bidding_Current_Price").effect("pulsate", { times: 5 }, 5000); 
             $("#hdnCurrentPrice").val(obj.CurrentPrice); 
            } 
            else { 
             $(".Bidding_Current_Price").stop(true, true); 
             $(".Bidding_Current_Price").removeAttr("style"); 
            } 

            // For ReservePrice Status 
            $("#spanReservePriceStatus").html(obj.ReservePriceStatus); 
            $("#smallReservePriceStatus").html(obj.ReservePriceStatus); 

            // For Bid Count 

            var spanBidCounter = $("#spanBidCount"); 

            $(spanBidCounter).text(obj.AcceptedActionCount); 


            var stringAppend = "<tr id='trhHighBidder'><td><strong>HighBidder</strong></td>"; 
            stringAppend += "<td>"; 
            if (obj.isAdmin == true) { 
             stringAppend += "<a id='anchorHighBid' href=" + obj.HighBidderURL + ">"; 
             stringAppend += "<span id='spanHighBidder'>" + obj.CurrentListingActionUserName + "</span>" 
             stringAppend += "</a>"; 
            } 
            else { 
             stringAppend += "<span id='spanHighBidderAnonymous'>" + obj.CurrentListingActionUserName + "</span>"; 
            } 
            stringAppend += "</td></tr>"; 

            if (obj.AcceptedActionCount.replace(/[^:]+:*/, "") > 0) { 
             if ($("#tblAuctionDetail").find("#rowHighBidder").length > 0) { 

              if ($("#tblAuctionDetail").find("#trhHighBidder").length > 0) { 
               $("#trhHighBidder").remove(); 
              } 
             } 
             else { 

              //add tr to table 
              if (!$("#tblAuctionDetail").find("#trhHighBidder").length > 0) { 
               $('#tblAuctionDetail > tbody > tr:eq(6)').after(stringAppend); 
              } 
             } 
            } 

            // For High Bidder 

            if (obj.isAdmin) { 

             var anchorElement = $("#anchorHighBid"); 
             $(anchorElement).attr("href", obj.HighBidderURL); 

             var spanHighBidder = $("#spanHighBidder"); 
             $(spanHighBidder).text(obj.CurrentListingActionUserName); 
            } 
            else { 
             var spanAdminHighBid = $("#spanHighBidderAnonymous"); 
             $(spanAdminHighBid).text(obj.CurrentListingActionUserName) 
            } 

           } 
          }, 
          error: function (xhr, textStatus, errorThrown) { 

          } 
         }); 
        } 
       }); 
      }; 

     }); 

Có điều gì sai với mã máy chủ của khách hàng hoặc máy chủ có thể cần được thay đổi để tránh những lỗi này xảy ra thường xuyên không? Mã 400 có xu hướng hiển thị gần như mỗi phút. Tôi rất mới để signalR và biết rất ít về cách làm cho mã hiệu quả với nó.

Đặt giá thầu thời gian thực trong trang web không hoạt động, chỉ để tìm cách tránh những lỗi liên tục này. Bất kỳ trợ giúp giải thích bất cứ điều gì về cách hoạt động của signalR được đánh giá cao.

Cảm ơn,

+2

Chúng tôi cũng gặp lỗi tương tự. Chúng tôi sử dụng dịch vụ như backplane. Tôi nghĩ rằng nó có liên quan với backplane và loadbalancer. Bạn có loadbalancer hoặc autoscaling? –

+0

Chúng tôi có cân bằng tải, thú vị. Tôi đã không nghĩ về điều này gây ra vấn đề này. –

+0

nội dung của phản hồi "Yêu cầu không hợp lệ" là gì? –

Trả lời

1

tôi muốn đưa ra một thử thay đổi phương thức di chuyển của SignalR: http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-javascript-client#transport và kiểm tra xem vấn đề vẫn còn.

Nếu có thể nhận UserAgent từ nhật ký Yêu cầu không hợp lệ, hãy cố gắng thu hẹp trình duyệt nào nhận được lỗi 400. Tôi nghĩ, có thể, một số trình duyệt không kết nối với phương thức vận chuyển chính xác.

Các vấn đề liên quan