Azure / azure-storage-net-data-movement

Azure Storage Data Movement Library for .Net
MIT License
276 stars 132 forks source link

CopyDirectoryAsync doesn´t work with asp.net mvc #215

Open FM1973 opened 4 years ago

FM1973 commented 4 years ago

Hi.

I implemented a "rename" function. I tested this function using a console application (.net 4.7) and it works like a charm. When I try to use the same function in a asp.net mvc 5 application it gets stuck. It creates the top "folder" and then... nothing. The function doesn´t even return.

Service: File Service SDK: 1.3.0.0 .net Framework 4.7

This is my function (I cant use async here, therefor I use .Result):

`public bool RenameFolder(string shareName, string folder, string newFolder) { var share = _client.GetShareReference(shareName); share.CreateIfNotExists();

        var rootDir = share.GetRootDirectoryReference();

        //Kopieren...
        var source = rootDir.GetDirectoryReference(folder);
        var target = rootDir.GetDirectoryReference(newFolder);

        var options = new CopyDirectoryOptions() { Recursive = true };

        var ctx = new DirectoryTransferContext();
        ctx.FileFailed += (sender, args) => { System.Diagnostics.Debug.WriteLine($"Failed: {args.Exception}"); };
        ctx.FileTransferred += (sender, args) => { System.Diagnostics.Debug.WriteLine($"Transferred: {args.Source}"); };
        ctx.FileSkipped += (sender, args) => { System.Diagnostics.Debug.WriteLine($"Skipped: {args.Source}"); };

        var status = TransferManager.CopyDirectoryAsync(source, target, CopyMethod.SyncCopy, options, ctx).Result;
        DeleteFolder(shareName, folder);

        return true;
    }`
blueww commented 4 years ago

@FM1973 As this works fine on .net 4.7, it looks not be your code issue. We have not see customer report issue on asp.net before, we need more time to look at it.

FM1973 commented 4 years ago

@blueww Hey there. Thanks for your feedback. I solved this problem without using TransferManager. All the best, Florian

fishinstew commented 4 years ago

I've been having the exact *nightmare with TransferManager and utilizing CopyDirectoryAsync. Everything works perfectly in a command line application. The moment i move into my MVC app it just 'freezes' when it hits the method CopyDirectoryAsync. I have confirmed this by simply creating a brand new MVC app, installing this nuget package, and testing.

Since i initially made this post, i cloned the source, created an MVC app and stepped through it. It appears to get stuck here: https://github.com/Azure/azure-storage-net-data-movement/blob/9b12ee1d7ee436c37c803d384903776554680175/lib/TransferJobs/HierarchyDirectoryTransfer.cs#L673

I also discovered this stack overflow article: https://stackoverflow.com/a/11243702/3845625

everything appears to work GREAT if you use a Task.Factory.StartNew and give it it's own context! var copyTask = await Task.Factory.StartNew(() => TransferManager.CopyDirectoryAsync(sourceRef, targetRef, CopyMethod.ServiceSideSyncCopy, options, null)); var result = await copyTask;