private void RunspacesLeakDetected(string key, string relatedBudgetKey) { int num = 0; IPowerShellBudget powerShellBudget = null; if (this.budgets.TryGetValue(key, out powerShellBudget)) { num = powerShellBudget.TotalActiveRunspacesCount; } if (powerShellBudget != null) { ExTraceGlobals.PublicPluginAPITracer.TraceError <string, string, int>(0L, "Connection leak detected for Key {0} in class {1}. Leaked value {2}.", key, base.GetType().ToString(), num); if (num > 0) { AuthZLogger.SafeAppendGenericError("WSManBudgetManagerBase.RunspacesLeakDetected", string.Format("Connection leak detected for Key {0} in class {1}. Leaked value {2}.", key, base.GetType(), num), false); TaskLogger.LogRbacEvent(TaskEventLogConstants.Tuple_PSConnectionLeakDetected, null, new object[] { key, base.GetType().ToString(), num }); this.UpdateConnectionLeakPerfCounter(num); } powerShellBudget.Dispose(); } if (num > 0 && relatedBudgetKey != null) { this.CorrectRelatedBudgetWhenLeak(relatedBudgetKey, num); } }
private void ThrottleRequest(HttpContext context) { ExTraceGlobals.HttpModuleTracer.TraceFunction((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Enter"); WinRMInfo winRMInfo = context.Items["X-RemotePS-WinRMInfo"] as WinRMInfo; if (winRMInfo == null) { ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] WinRMInfo = null."); return; } string action = winRMInfo.Action; if (string.IsNullOrEmpty(action)) { ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] WinRMInfo.Action = null."); return; } if (!action.EndsWith(":Command", StringComparison.OrdinalIgnoreCase) && !action.Equals("Command", StringComparison.OrdinalIgnoreCase)) { ExTraceGlobals.HttpModuleTracer.TraceDebug <string>((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Not Command Request. WinRMInfo.Action = {0}.", action); return; } IPowerShellBudget powerShellBudget = null; OverBudgetException ex = null; try { try { using (new MonitoredScope("ThrottlingHttpModule", "GetBudget", HttpModuleHelper.HttpPerfMonitors)) { powerShellBudget = this.GetBudget(context); } if (powerShellBudget == null) { ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] budget = null."); return; } using (new MonitoredScope("ThrottlingHttpModule", "CheckBudgetAndStartCmdlet", HttpModuleHelper.HttpPerfMonitors)) { powerShellBudget.StartCmdlet(null); powerShellBudget.TryCheckOverBudget(CostType.CMDLET, out ex); } } finally { if (powerShellBudget != null) { powerShellBudget.Dispose(); } } if (ex != null) { string windowsLiveId = context.CurrentUserToken().WindowsLiveId; if (windowsLiveId != null) { FailFastUserCache.Instance.AddUserToCache(windowsLiveId, BlockedType.NewRequest, TimeSpan.Zero); HttpLogger.SafeAppendColumn(RpsCommonMetadata.ContributeToFailFast, "AuthZ-UserSelf", LoggerHelper.GetContributeToFailFastValue("User", windowsLiveId, BlockedType.NewRequest.ToString(), -1.0)); } HttpModuleHelper.EndPowerShellRequestWithFriendlyError(context, FailureCategory.AuthZ, ex.GetType().Name, Strings.ErrorOperationTarpitting(ex.BackoffTime / 1000) + string.Format("{2}Policy: {0}; {2}Snapshot: {1}", ex.ThrottlingPolicyDN, ex.Snapshot, Environment.NewLine), "ThrottlingHttpModule", false); } } catch (Exception ex2) { if (!(ex2 is ThreadAbortException)) { HttpLogger.SafeAppendGenericError("ThrottlingHttpModule", ex2, new Func <Exception, bool>(KnownException.IsUnhandledException)); ExTraceGlobals.HttpModuleTracer.TraceError <Exception>((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Get un-Excpected Exception. {0}", ex2); } } }