Closed i10416 closed 1 year ago
I suspect openConnection for ArtifactRegistry is handled by default URLStreamHandler instead of GcsArtifactRegistryUrlHandler as URLStreamHandler doc says
abstract class URLStreamHandler: URLStreamHandler The abstract class URLStreamHandler is the common superclass for all stream protocol handlers. A stream protocol handler knows how to make a connection for a particular protocol type, such as http or https.
In most cases, an instance of a URLStreamHandler subclass is not created directly by an application. Rather, the first time a protocol name is encountered when constructing a URL, the appropriate stream protocol handler is automatically loaded
So, it would be possible that GcsArtifactRegistryUrlConnection does not work properly.
Hm, this is interesting. So I assume this happens only for relatively big files? Let me test it in my env first.
I was able to load GcsArtifactRegistryUrlHandler properly by the following change, thus GcsArtifactRegistryUrlConnection#getOutputStream
is properly called.
It seems that registered custom Url handler is loaded when it tries to open connection for "artifact-registry://" protocol.
I think it was too early to convert "artifact-registry://" to "https://" in current codebase.
override def upload( src: File, dest: URL, l: CopyProgressListener ): Unit = {
logger.info(
s"Publishing artifact to '${dest}'..."
)
val event = new CopyProgressEvent()
Option( l ).foreach( _.start( event ) )
- val genericUrl = GcsArtifactRegistryGenericUrlFactory.createFromUrl( dest )
val contentType = getContentType( dest )
val httpRequest = googleHttpRequestFactory.buildPutRequest(
- genericUrl,
+ new GenericUrl(dest),
new HttpContent() {
override def getLength: Long = src.length()
override def getType: String = contentType
override def retrySupported(): Boolean = true
override def writeTo( out: OutputStream ): Unit = {
println(s"[DEBUG] start transfering data from ${src} to ${out}")
Files.copy( src.toPath, out )
out.close()
}
}
)
This change is not clear why would help you, since GenericUrl is just dumb data class without side effects. Probably there is some race condition issue, and it just changes timing for you and there is still a problem if it exists.
Ah, you didn't just change the order, but also the URL still pointing to previous scheme. 🤔
I suspect openConnection for ArtifactRegistry is handled by default URLStreamHandler instead of GcsArtifactRegistryUrlHandler
This was actually even designed like that: GcsArtifactRegistryIvyUrlHandler
didn't have to use GcsArtifactRegistryUrlConnection
anymore since it also uses googleHttpRequestFactory
and common HTTPS is enough.
Please clarify a bit more your case:
Does it happen all the time (100% reproducible?)
"java.io.IOException: Error writing request body to server" always happen when I run publish command.
Does it happen regardless of the file sizes?
I'm not sure it depends on file sizes. Sorry.
At first, I suspected that changing HttpConnection settings like setFixedLengthStreamingMode
would solve the issue, but in vain.
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT.pom'...
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT.pom.sha1'...
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT.pom.md5'...
[info] published sbt-gcs-plugin-playground-artifact-publish_2.12 to artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT.pom
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT.jar'...
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT.jar.sha1'...
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT.jar.md5'...
[info] published sbt-gcs-plugin-playground-artifact-publish_2.12 to artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT.jar
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT-sources.jar'...
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT-sources.jar.sha1'...
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT-sources.jar.md5'...
[info] published sbt-gcs-plugin-playground-artifact-publish_2.12 to artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT-sources.jar
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT-javadoc.jar'...
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT-javadoc.jar.sha1'...
[info] Publishing artifact to 'artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT-javadoc.jar.md5'...
[info] published sbt-gcs-plugin-playground-artifact-publish_2.12 to artifactregistry://europe-north1-maven.pkg.dev/latestbit/latestbit-artifacts-snapshots/org/latestbit/sbt-gcs-plugin-playground-artifact-publish_2.12/0.0.12-SNAPSHOT/sbt-gcs-plugin-playground-artifact-publish_2.12-0.0.12-SNAPSHOT-javadoc.jar
[success] Total time: 28 s, completed 12 Apr 2023, 17:47:15
I just tested publishing 100Mb jar file for my test registry and it worked.
Can you reproduce this issue with:
sbt
in that dirproject sbtGcsArtifactRepositoryPlaygroundToPublish
publish
My environment:
java -version
openjdk version "11.0.18" 2023-01-17 LTS
OpenJDK Runtime Environment Corretto-11.0.18.10.1 (build 11.0.18+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.18.10.1 (build 11.0.18+10-LTS, mixed mode)
sbt version in this project: 1.8.2
sbt script version: 1.8.2
Also, I have multiple pipelines using this plugin, and they never failed. We have some differences that we need to find.
Also, I have multiple pipelines using this plugin, and they never failed. We have some differences that we need to find.
On reading this, I looked again and I found I made a silly mistake 😰
So sorry, I found my artifact registry path was wrong, which resulted in "Error writing request body to server" 😅
This solves my issue.
- "My Maven Artifact Registry" at "artifactregistry://asia-northeast1-maven.pkg.dev/<project>//<registry>"
+ "My Maven Artifact Registry" at "artifactregistry://asia-northeast1-maven.pkg.dev/<project>/<registry>"
Thanks for taking your time to identify error causes.
On reading this, I looked again and I found I made a silly mistake cold_sweat
Great you found the problem. Probably I need to think about error handling to make it obvious when it fails with cryptic errors like this.
Yeah, and I don't think GcsArtifactRegistryUrlConnection needs concrete implementation, does it?
Solved: I was so stupid that I overlooked my mistake.
https://github.com/abdolence/sbt-gcs-resolver/issues/43#issuecomment-1505547355
I ran into error when I tried to upload package to GCP Artifact Registry. As I mention later, however, manually uploading jar works. So, I guess UrlConnection and/or UrlHandler are/is the culpritPerhaps, we needconnection.setFixedLengthStreamingMode(size)
to send a larger fileenvironment and full stacktrace
NOTE: To my surprise, uploading jar by hand works
Strangely, I can manually upload jar to ArtifactRegistry by the following code.
I suspected we should use multipart request instead of
HttpContent
inGcsArtifactRegistryIvyUrlHandler
to transfer a large file, but I was wrong.It turned out that uploading without multipart also works.
There is another strange behavior, which may or may not be relevant to this error. The size of my jar before upload is 575928, but it increases to 576106 after multipart upload and download while the size of my pom does not change after downloading uploaded one.