abelsilva / swaggerwcf

Swagger for WCF
Apache License 2.0
132 stars 95 forks source link

ZIPArchive API use in StaticContent.cs is not thread safe #173

Open ghost opened 6 years ago

ghost commented 6 years ago

We use this component and experienced deadlocks with multiple threads calling ZipArchive.Entries.get(). The code using ZipArchive in StaticContent.cs is not thread safe (non-static members of ZipArchive/ZipArchiveEntry are not thread safe) nor is enumerating the collection of ZipArchiveEntry's. We fixed by putting a lock around:

ZipArchiveEntry file = _archiveCustom.Entries.FirstOrDefault(entry => entry.FullName == filename); file.Open();

We also copy the stream from file.open() into a MemoryStream and return that instead of the underlying stream.

justin0522 commented 6 years ago

here is my advice: there are two methods in ServiceContract ISwaggerWcfEndpoint, remove the second (StaticContent), host the index.html by yourself, keep the first which provider the swagger.json content.