0

我们这里发生了一个奇怪的情况。我们已经设置了 NuGet 库的本地安装(与支持http://Nuget.org的代码相同)。IIS 和 DB 在同一个盒子上。IIS 应用程序池已配置为在域用户下运行,该域用户也是机器上的本地管理员,并且具有“作为服务登录的权限”权限。现在当有人(成功登录后)尝试上传包时,上传包业务需要很长时间并最终抛出“底层提供程序无法打开”错误

  [TimeoutException: Transaction Timeout]

[TransactionException: The operation is not valid for the state of the transaction.]
   System.Transactions.TransactionState.EnlistPromotableSinglePhase(InternalTransaction tx, IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Transaction atomicTransaction) +53
   System.Transactions.Transaction.EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification) +241
   System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx) +273
   System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction) +150
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +2647
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +89
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6372062
   System.Data.SqlClient.SqlConnection.Open() +300
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +67

[EntityException: The underlying provider failed on Open.]
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +11109230
   System.Data.EntityClient.EntityConnection.Open() +142
   System.Data.Objects.ObjectContext.EnsureConnection() +97
   System.Data.Objects.ObjectContext.ExecuteStoreQueryInternal(String commandText, String entitySetName, MergeOption mergeOption, Object[] parameters) +109
   System.Data.Objects.ObjectContext.ExecuteStoreQuery(String commandText, Object[] parameters) +87
   System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(String sql, Object[] parameters) +118
   System.Data.Entity.Internal.InternalContext.ExecuteSqlQueryAsIEnumerable(String sql, Object[] parameters) +85
   System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(Type elementType, String sql, Object[] parameters) +241
   System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator() +34
   System.Data.Entity.Internal.InternalSqlQuery`1.GetEnumerator() +28
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +382
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +80
   NuGetGallery.LuceneIndexingService.GetPackages(DbContext context, Nullable`1 dateTime) in C:\Source\DotNetDevEng.CitiNuGet\Gallery\DEV\Website\Infrastructure\Lucene\LuceneIndexingService.cs:55
   NuGetGallery.LuceneIndexingService.UpdateIndex() in C:\Source\DotNetDevEng.CitiNuGet\Gallery\DEV\Website\Infrastructure\Lucene\LuceneIndexingService.cs:32
   NuGetGallery.PackageService.CreatePackage(IPackage nugetPackage, User currentUser) in C:\Source\DotNetDevEng.CitiNuGet\Gallery\DEV\Website\Services\PackageService.cs:61
   NuGetGallery.PackagesController.VerifyPackage(Nullable`1 listed) in C:\Source\DotNetDevEng.CitiNuGet\Gallery\DEV\Website\Controllers\PackagesController.cs:503
   lambda_method(Closure , ControllerBase , Object[] ) +121
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +248
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +125
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +640
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +640
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +312
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +691
   System.Web.Mvc.Controller.ExecuteCore() +162
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +305
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

有趣的是,如果我将 IIS 应用程序池切换为在内置的“LocalSystem”帐户下运行,所有这些问题都会消失。我们要使用的域用户已临时设置为 NuGetGallery 数据库的数据库所有者,但它没有帮助。

谁能建议我们在这里可能缺少的设置/配置?

4

1 回答 1

0

这是由于代码中正在进行的环境事务。该代码依赖于 TransactionScope 类来管理各种事务,这些事务在嵌套时会陷入困境。如果有人尝试上传大小超过 10MB 的包,事情就会变得特别糟糕。一旦我们调整了盒子上的 MSDTC,应用程序就开始表现得稍微正常了。然而,它在自己的事务中仍然间歇性地陷入僵局,所以现在我们决定从包上传位中删除事务。

对于遇到此问题的其他人,我会推荐这两个中的任何一个

  1. 注释掉任何对 TransactionScope 的引用

Services\PackageService.cs(方法 CreatePackage,第 48 行)

  using (var tx = new TransactionScope())
            {
                using (var stream = nugetPackage.GetStream())
                {
                    UpdateIsLatest(packageRegistration);
                    packageRegistrationRepo.CommitChanges();
                    packageFileSvc.SavePackageFile(package, stream);
                    tx.Complete();
                }
            }

并在 Controller\PackageController.cs 方法 VerifyPackage(bool? Listed) 第 501 行

 using (var tx = new TransactionScope())
            {

                package = packageSvc.CreatePackage(nugetPackage, currentUser);
                packageSvc.PublishPackage(package.PackageRegistration.Id, package.Version);
                if (listed.HasValue && listed.Value == false)
                    packageSvc.MarkPackageUnlisted(package);
                uploadFileSvc.DeleteUploadFile(currentUser.Key);
                tx.Complete();
            }

2 取消注释这些行并遵循此处提到的方法http://blogs.msdn.com/b/dbrowne/archive/2010/05/21/using-new-transactionscope-considered-harmful.aspx

基本上创建一个可以与 SQL Server 一起工作的事务范围。在 InfraStructureFolder 中创建一个新类,将其命名为 TranscationUtils 并复制其中的代码。然后使用块看起来像

using (var tx = new TransactionUtils.CreateTransactionScope()){

//cod here
tx.Complete();
}

但是,第二种方法可能会导致另一个服务器错误,这又与您可以为 TransactionScope 指定的默认超时有关。我们个人决定采用方法 1 并暂时注释掉所有 TransactionScope 引用。

于 2012-05-03T08:52:54.817 回答