IDEA crashes when I use a plugin for generating code which calls a native Go library

Answered

I developed a plugin dependence on a Go library (build in c-shared mode). It work fine in sandbox, but after installed, it crash the IDEA when I click the "生成" ("Generate") button. And the Native library didn't print any log to idea.log (but print to terminal in sandbox environment).

I finally found the reason: big size byte array read from file cause the memory problem. But I can't confirm without log or dump file.

I put the plugin and source code in attachment and hope for help. My system is Mac OS Monterey 12.0.1, and the Go library was build in go 1.17.

  • Upload id: 2022_05_20_UeKHXmzPMsFoY2pB (files: gormGenPlugin-1.0.zip, gorm_gen_plugin.zip)
  • Upload id: 2022_05_20_DwRVy1uEeZeKUghb (file: idea-logs-20220519-2032483452445316971280452.zip)
22 comments
Comment actions Permalink

Hi,

Please provide us with more details.

Is this plugin developed for GoLand? Is the crashing code executed in some extension point? If yes, then please clarify where exactly it crashes.

0
Comment actions Permalink

https://github.com/zhaozhihom/gogenfuncThis is the repo build the libgormgen.dylib

github.com/zhaozhihom/gen@v0.1.0/generator.go:493

If the content size more than 2kb(maybe more, I didn't test), the VM crash.

 

 

0
Comment actions Permalink

Yes, it was developed for goland, and it crashed in goland the same performance.

0
Comment actions Permalink

Hello,

I've tried to reproduce it with your version of the plugin in #GO-221.5591.52, built on May 10, 2022 to no avail.

Could you please share a code snippet on where you invoked Generate action?

0
Comment actions Permalink

OK,Actually I use jna to call the function of go library(here https://github.com/zhaozhihom/gogenfunc) , below is the code snippet

I have provided the source code in the attachment. The purpose of this code is to get the db connect message(url, username, password), and generate models and CRUD code from tables. You can install the plugin I provided above, and try it. The position of the Action is Tools|Gorm Generator

Create a new connection:

Choose tables and click "Generate":

The crash happened in this step. What confused me is the plugin worked normally in sandbox.

 

 

0
Comment actions Permalink

Reproduced, it looks like a memory issue. You may reproduce the problem in the sandbox by using the latest version of GoLand/IntelliJ IDEA. I see that currently, you are using 2021.2 instead of 2022.1.1.

0
Comment actions Permalink

This is my project SDK config, it is 2022.1.  Is there something wrong...

0
Comment actions Permalink

Are you using the Run Plugin Gradle configuration or not? It uses the 2021 version of IntelliJ IDEA.

0
Comment actions Permalink
plugins {
id("java")
id("org.jetbrains.intellij") version "1.6.0"
}

group = "org.bytedance"
version = "1.0"

repositories {
mavenCentral()
}

// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij {
version.set("2022.1.1")

plugins.set(listOf("com.intellij.java"))
}

tasks {
// Set the JVM compatibility versions
withType<JavaCompile> {
sourceCompatibility = "11"
targetCompatibility = "11"
}

patchPluginXml {
sinceBuild.set("212")
untilBuild.set("222.*")
}

signPlugin {
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
privateKey.set(System.getenv("PRIVATE_KEY"))
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
}

publishPlugin {
token.set(System.getenv("PUBLISH_TOKEN"))
}
}

dependencies {
implementation("mysql:mysql-connector-java:8.0.29")
}

I upgrade the intellij version to 2022.1.1. It still dosen't reproduce in sandbox.

0
Comment actions Permalink

Is there a test data that I could use to fill in fields for a remote connection to a database? I was able to reproduce it once on the database connection pop-up, but no way to do it again with the same steps.

By the way, you can also enable Internal Mode in GoLand to see stacktraces in the same way as in sandbox: https://plugins.jetbrains.com/docs/intellij/enabling-internal.html

0
Comment actions Permalink

<credentials>

This is my test db.

A question: I have enabled Internal Mode and see the "Internal Actions". How can I see the stacktraces?

0
Comment actions Permalink

Does it have any progress?  I don't know how to see stacktraces.

0
Comment actions Permalink

Please try to start GoLand from CLI to see if it produces a bit more details: https://intellij-support.jetbrains.com/hc/en-us/articles/360011901879

0
Comment actions Permalink

Yes, it worked if started from CLI, and print the log I expected.  But it dosen't work if I start it from tool-box. What is the reason could be?

0
Comment actions Permalink

Maybe I can share the screen,it will be more efficient.

0
Comment actions Permalink

Do you mean that there are no logs with crashes or plugin works as expected if you've started GoLand from CLI?

You can upload a small screencast to https://uploads.jetbrains.com/ and provide its ID.

0
Comment actions Permalink

From Cli: work, not crash and get logs

Form ToolBox: not work,crash without logs

0
Comment actions Permalink

I suspect that the reason could be in the environment – GoLand inherits all environments from Terminal, but it doesn't do the same thing for Toolbox App.

Can you upload a screencast to https://uploads.jetbrains.com/ and provide its ID (with/without crash)?

0
Comment actions Permalink

I print all environment variables of both way, toolbox lack of some variables, which could be the reason?

From Terminal:

PATH:/usr/local/opt/openjdk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/puppetlabs/bin:/usr/local/go/bin:/Users/bytedance/go/bin
LC_TERMINAL:iTerm2
TERM:xterm-256color
LANG:zh_CN.UTF-8
COMMAND_MODE:unix2003
ITERM_SESSION_ID:w0t2p0:3F486E0C-B194-4AF4-9D06-C6746037651D
COLORTERM:truecolor
LOGNAME:bytedance
XPC_SERVICE_NAME:0
TERM_PROGRAM_VERSION:3.4.15
PWD:/Users/bytedance/Library/Application Support/JetBrains/Toolbox/apps/Goland/ch-0/221.5921.26/GoLand.app/Contents/MacOS
_:/Users/bytedance/Library/Application Support/JetBrains/Toolbox/apps/Goland/ch-0/221.5921.26/GoLand.app/Contents/MacOS/./goland
__CFBundleIdentifier:com.googlecode.iterm2
SHELL:/usr/local/bin/zsh
LC_TERMINAL_VERSION:3.4.15
TERM_PROGRAM:iTerm.app
PAGER:less
LSCOLORS:Gxfxcxdxbxegedabagacad
GOPATH:/Users/bytedance/go
OLDPWD:/Users/bytedance/Library/Application Support/JetBrains/Toolbox/apps/Goland/ch-0/221.5921.26/GoLand.app/Contents
USER:bytedance
ZSH:/Users/bytedance/.oh-my-zsh
GO111MODULE:on
TMPDIR:/var/folders/68/hszw033x1h35sc2j05wpzgvw0000gp/T/
ITERM_PROFILE:Default
SSH_AUTH_SOCK:/private/tmp/com.apple.launchd.j3vAXFq7fp/Listeners
XPC_FLAGS:0x0
TERM_SESSION_ID:w0t2p0:3F486E0C-B194-4AF4-9D06-C6746037651D
__CF_USER_TEXT_ENCODING:0x1F6:0x19:0x34
LESS:-R
COLORFGBG:7;0
SHLVL:1
HOME:/Users/bytedance
 
From Toolbox:
 
PATH:/usr/bin:/bin:/usr/sbin:/sbin
__CFBundleIdentifier:com.jetbrains.goland
SHELL:/usr/local/bin/zsh
USER:bytedance
TMPDIR:/var/folders/68/hszw033x1h35sc2j05wpzgvw0000gp/T/
COMMAND_MODE:unix2003
SSH_AUTH_SOCK:/private/tmp/com.apple.launchd.j3vAXFq7fp/Listeners
XPC_FLAGS:0x0
__CF_USER_TEXT_ENCODING:0x1F6:0x19:0x34
LOGNAME:bytedance
XPC_SERVICE_NAME:application.com.jetbrains.goland.24650033.24652306
TOOLBOX_VERSION:1.24.12080
HOME:/Users/bytedance
 
0
Comment actions Permalink

Yes, that could be the reason, especially if your application operates with some variables.

0
Comment actions Permalink

How can I add variables when start the goland or in runtime?

0
Comment actions Permalink

You can start Toolbox App via CLI and it should inherit environments variables from CLI to desktop applications: /Applications/JetBrains\ Toolbox.app/Contents/MacOS/jetbrains-toolbox

0

Please sign in to leave a comment.