Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetClipboardData() fails on buildkite windows CI #46981

Closed
staticfloat opened this issue Sep 29, 2022 · 14 comments · Fixed by #47311
Closed

GetClipboardData() fails on buildkite windows CI #46981

staticfloat opened this issue Sep 29, 2022 · 14 comments · Fixed by #47311
Labels
ci Continuous integration system:windows Affects only Windows

Comments

@staticfloat
Copy link
Member

This clipboard test in InteractiveUtils is failing with the following error:

Expression: clipboard() == ""
--
  | SystemError: GetClipboardData: Invalid clipboard format
  | Stacktrace:
  | [1] windowserror(p::Symbol, code::UInt32; extrainfo::Nothing)
  | @ Base .\error.jl:191
  | [2] windowserror(p::Symbol, code::UInt32)
  | @ Base .\error.jl:191
  | [3] cleanup
  | @ C:\buildkite-agent\builds\win2k22-amdci6-4\julialang\julia-master\julia-9fd408723a\share\julia\stdlib\v1.9\InteractiveUtils\src\clipboard.jl:118 [inlined]
  | [4] clipboard()
  | @ InteractiveUtils C:\buildkite-agent\builds\win2k22-amdci6-4\julialang\julia-master\julia-9fd408723a\share\julia\stdlib\v1.9\InteractiveUtils\src\clipboard.jl:125
  | [5] macro expansion
  | @ C:\buildkite-agent\builds\win2k22-amdci6-4\julialang\julia-master\julia-9fd408723a\share\julia\stdlib\v1.9\Test\src\Test.jl:477 [inlined]
  | [6] top-level scope
  | @ C:\buildkite-agent\builds\win2k22-amdci6-4\julialang\julia-master\julia-9fd408723a\share\julia\stdlib\v1.9\InteractiveUtils\test\runtests.jl:584

Manually running this on one of the new buildkite workers, I can confirm that clearing the clipboard and then attempting to get the clipboard throws an error, rather than returning an empty string:

julia> clipboard("something")
       @test clipboard() == "something"
       ccall((:OpenClipboard, "user32"), stdcall, Cint, (Ptr{Cvoid},), C_NULL) == 0 && Base.windowserror("OpenClipboard")
       try
           ccall((:EmptyClipboard, "user32"), stdcall, Cint, ()) == 0 && Base.windowserror("EmptyClipboard")
       finally
           ccall((:CloseClipboard, "user32"), stdcall, Cint, ()) == 0 && Base.windowserror("CloseClipboard")
       end
       clipboard()
ERROR: SystemError: GetClipboardData: Invalid clipboard format 
Stacktrace:
 [1] windowserror(p::Symbol, code::UInt32; extrainfo::Nothing)
   @ Base .\error.jl:191
 [2] windowserror(p::Symbol, code::UInt32)
   @ Base .\error.jl:191
 [3] cleanup
   @ C:\Program Files\Julia-1.8.0\share\julia\stdlib\v1.8\InteractiveUtils\src\clipboard.jl:118 [inlined]
 [4] clipboard()
   @ InteractiveUtils C:\Program Files\Julia-1.8.0\share\julia\stdlib\v1.8\InteractiveUtils\src\clipboard.jl:125
 [5] top-level scope
   @ REPL[17]:9
@staticfloat staticfloat added system:windows Affects only Windows ci Continuous integration labels Sep 29, 2022
@inkydragon
Copy link
Member

Cannot be reproduced with

  • cmd /c ver: Win 10.0.19044.2006 (21H2)
  • julia: Version 1.9.0-DEV.1472 (2022-09-30) Commit 90dbc5d

What is the Windows version of our CI?

@gbaraldi
Copy link
Member

During the build we print
MINGW64_NT-10.0-20348 but I don't know if that tells us anything

@staticfloat
Copy link
Member Author

The windows version is Windows Server 2022, build 20348, you can see the full systeminfo output here, because I'm trying to debug a transient failure at the moment.

@inkydragon
Copy link
Member

inkydragon commented Oct 2, 2022

Windows Server 2022, build 20348

Update: #46981 (comment)
Still Cannot be reproduced with:

  • Windows Server 2022 Datacenter 10.0.20348.825
  • julia Version 1.8.2 (2022-09-29) x64

Is this error related to the version of julia?

@DilumAluthge
Copy link
Member

Is it because we are running Windows inside a VM?

@staticfloat
Copy link
Member Author

Is this error related to the version of julia?

Can you try downloading the .tar.gz that buildkite uploads? E.g. here's a build from latest master: https://buildkite.com/organizations/julialang/pipelines/julia-master/builds/16462/jobs/01839d71-b070-4763-b2c9-4d9f76f2bf4e/artifacts/01839da6-9fff-4560-9aca-47ffbb323e72

@inkydragon
Copy link
Member

Can you try downloading the .tar.gz that buildkite uploads?

I can confirm that this issue can be reproduced on Win Srv 2022 by using the buildkite upload.

@staticfloat
Copy link
Member Author

Fascinating! So there's some difference in what we built.... could it be that we're linking against a slightly different windows runtime library, or something like that?

@inkydragon
Copy link
Member

sf: Can you dump the Libdl.dllist() for the two windows builds, so we can see if they’re linking against different runtime libraries or something?

Win10 Pro x64 + dccf331

Libdl.dllist()
julia> using Libdl; Libdl.dllist() |> sort .|> println;
C:\WINDOWS\SYSTEM32\CRYPTBASE.DLL
C:\WINDOWS\SYSTEM32\IPHLPAPI.DLL
C:\WINDOWS\SYSTEM32\SSPICLI.DLL
C:\WINDOWS\SYSTEM32\Secur32.dll
C:\WINDOWS\SYSTEM32\UMPDC.dll
C:\WINDOWS\SYSTEM32\USERENV.dll
C:\WINDOWS\SYSTEM32\WINMM.dll
C:\WINDOWS\SYSTEM32\dbghelp.dll
C:\WINDOWS\SYSTEM32\ntdll.dll
C:\WINDOWS\SYSTEM32\powrprof.dll
C:\WINDOWS\System32\ADVAPI32.dll
C:\WINDOWS\System32\CRYPT32.dll
C:\WINDOWS\System32\CRYPTSP.dll
C:\WINDOWS\System32\GDI32.dll
C:\WINDOWS\System32\IMM32.DLL
C:\WINDOWS\System32\KERNEL32.DLL
C:\WINDOWS\System32\KERNELBASE.dll
C:\WINDOWS\System32\PSAPI.DLL
C:\WINDOWS\System32\RPCRT4.dll
C:\WINDOWS\System32\SHELL32.dll
C:\WINDOWS\System32\USER32.dll
C:\WINDOWS\System32\WS2_32.dll
C:\WINDOWS\System32\bcrypt.dll
C:\WINDOWS\System32\bcryptPrimitives.dll
C:\WINDOWS\System32\combase.dll
C:\WINDOWS\System32\gdi32full.dll
C:\WINDOWS\System32\msvcp_win.dll
C:\WINDOWS\System32\msvcrt.dll
C:\WINDOWS\System32\ole32.dll
C:\WINDOWS\System32\sechost.dll
C:\WINDOWS\System32\ucrtbase.dll
C:\WINDOWS\System32\win32u.dll
C:\WINDOWS\system32\mswsock.dll
C:\WINDOWS\system32\rsaenh.dll
C:\WINDOWS\system32\uxtheme.dll
V:\julia-dccf331061\bin\julia.exe
V:\julia-dccf331061\bin\libLLVM-14jl.dll
V:\julia-dccf331061\bin\libamd.dll
V:\julia-dccf331061\bin\libatomic-1.dll
V:\julia-dccf331061\bin\libblastrampoline.dll
V:\julia-dccf331061\bin\libcamd.dll
V:\julia-dccf331061\bin\libccolamd.dll
V:\julia-dccf331061\bin\libcholmod.DLL
V:\julia-dccf331061\bin\libcolamd.dll
V:\julia-dccf331061\bin\libcurl-4.dll
V:\julia-dccf331061\bin\libgcc_s_seh-1.dll
V:\julia-dccf331061\bin\libgfortran-5.dll
V:\julia-dccf331061\bin\libgmp-10.dll
V:\julia-dccf331061\bin\libgmp.DLL
V:\julia-dccf331061\bin\libgomp-1.dll
V:\julia-dccf331061\bin\libjulia-codegen.dll
V:\julia-dccf331061\bin\libjulia-internal.dll
V:\julia-dccf331061\bin\libjulia.dll
V:\julia-dccf331061\bin\libmbedcrypto.dll
V:\julia-dccf331061\bin\libmpfr.DLL
V:\julia-dccf331061\bin\libnghttp2-14.dll
V:\julia-dccf331061\bin\libopenblas64_.dll
V:\julia-dccf331061\bin\libopenlibm.dll
V:\julia-dccf331061\bin\libpcre2-8.DLL
V:\julia-dccf331061\bin\libquadmath-0.dll
V:\julia-dccf331061\bin\libssh2.dll
V:\julia-dccf331061\bin\libssp-0.dll
V:\julia-dccf331061\bin\libstdc++-6.dll
V:\julia-dccf331061\bin\libsuitesparseconfig.dll
V:\julia-dccf331061\bin\libwinpthread-1.dll
V:\julia-dccf331061\bin\libz.dll
V:\julia-dccf331061\lib\julia\sys.dll

Win Srv 2022 x64 + dccf331

Libdl.dllist()
julia> using Libdl; Libdl.dllist() |> sort .|> println;
C:\WINDOWS\SYSTEM32\CRYPTBASE.DLL
C:\WINDOWS\SYSTEM32\IPHLPAPI.DLL
C:\WINDOWS\SYSTEM32\SSPICLI.DLL
C:\WINDOWS\SYSTEM32\Secur32.dll
C:\WINDOWS\SYSTEM32\UMPDC.dll
C:\WINDOWS\SYSTEM32\USERENV.dll
C:\WINDOWS\SYSTEM32\WINMM.dll
C:\WINDOWS\SYSTEM32\apphelp.dll
C:\WINDOWS\SYSTEM32\dbghelp.dll
C:\WINDOWS\SYSTEM32\ntdll.dll
C:\WINDOWS\SYSTEM32\powrprof.dll
C:\WINDOWS\System32\ADVAPI32.dll
C:\WINDOWS\System32\CRYPT32.dll
C:\WINDOWS\System32\CRYPTSP.dll
C:\WINDOWS\System32\GDI32.dll
C:\WINDOWS\System32\IMM32.DLL
C:\WINDOWS\System32\KERNEL32.DLL
C:\WINDOWS\System32\KERNELBASE.dll
C:\WINDOWS\System32\PSAPI.DLL
C:\WINDOWS\System32\RPCRT4.dll
C:\WINDOWS\System32\SHELL32.dll
C:\WINDOWS\System32\USER32.dll
C:\WINDOWS\System32\WS2_32.dll
C:\WINDOWS\System32\bcryptPrimitives.dll
C:\WINDOWS\System32\combase.dll
C:\WINDOWS\System32\gdi32full.dll
C:\WINDOWS\System32\msvcp_win.dll
C:\WINDOWS\System32\msvcrt.dll
C:\WINDOWS\System32\ole32.dll
C:\WINDOWS\System32\sechost.dll
C:\WINDOWS\System32\ucrtbase.dll
C:\WINDOWS\System32\win32u.dll
C:\WINDOWS\system32\mswsock.dll
C:\WINDOWS\system32\rsaenh.dll
C:\WINDOWS\system32\uxtheme.dll
V:\julia-dccf331061\bin\julia.exe
V:\julia-dccf331061\bin\libLLVM-14jl.dll
V:\julia-dccf331061\bin\libamd.dll
V:\julia-dccf331061\bin\libatomic-1.dll
V:\julia-dccf331061\bin\libblastrampoline.dll
V:\julia-dccf331061\bin\libcamd.dll
V:\julia-dccf331061\bin\libccolamd.dll
V:\julia-dccf331061\bin\libcholmod.DLL
V:\julia-dccf331061\bin\libcolamd.dll
V:\julia-dccf331061\bin\libcurl-4.dll
V:\julia-dccf331061\bin\libgcc_s_seh-1.dll
V:\julia-dccf331061\bin\libgfortran-5.dll
V:\julia-dccf331061\bin\libgmp-10.dll
V:\julia-dccf331061\bin\libgmp.DLL
V:\julia-dccf331061\bin\libgomp-1.dll
V:\julia-dccf331061\bin\libjulia-codegen.dll
V:\julia-dccf331061\bin\libjulia-internal.dll
V:\julia-dccf331061\bin\libjulia.dll
V:\julia-dccf331061\bin\libmbedcrypto.dll
V:\julia-dccf331061\bin\libmpfr.DLL
V:\julia-dccf331061\bin\libnghttp2-14.dll
V:\julia-dccf331061\bin\libopenblas64_.dll
V:\julia-dccf331061\bin\libopenlibm.dll
V:\julia-dccf331061\bin\libpcre2-8.DLL
V:\julia-dccf331061\bin\libquadmath-0.dll
V:\julia-dccf331061\bin\libssh2.dll
V:\julia-dccf331061\bin\libssp-0.dll
V:\julia-dccf331061\bin\libstdc++-6.dll
V:\julia-dccf331061\bin\libsuitesparseconfig.dll
V:\julia-dccf331061\bin\libwinpthread-1.dll
V:\julia-dccf331061\bin\libz.dll
V:\julia-dccf331061\lib\julia\sys.dll
$ diff -u Win10.txt WinSrv2022.txt 
--- Win10.txt   2022-10-05 10:47:28.954767400 +0800
+++ WinSrv2022.txt      2022-10-05 10:48:43.546736400 +0800
@@ -6,6 +6,7 @@
 C:\WINDOWS\SYSTEM32\UMPDC.dll
 C:\WINDOWS\SYSTEM32\USERENV.dll
 C:\WINDOWS\SYSTEM32\WINMM.dll
+C:\WINDOWS\SYSTEM32\apphelp.dll
 C:\WINDOWS\SYSTEM32\dbghelp.dll
 C:\WINDOWS\SYSTEM32\ntdll.dll
 C:\WINDOWS\SYSTEM32\powrprof.dll
@@ -21,7 +22,6 @@
 C:\WINDOWS\System32\SHELL32.dll
 C:\WINDOWS\System32\USER32.dll
 C:\WINDOWS\System32\WS2_32.dll
-C:\WINDOWS\System32\bcrypt.dll
 C:\WINDOWS\System32\bcryptPrimitives.dll
 C:\WINDOWS\System32\combase.dll
 C:\WINDOWS\System32\gdi32full.dll

@staticfloat
Copy link
Member Author

I hypothesize that the buildkite build links against some libraries, whereas the non-buildkite build does not. Can you run Libdl.dllist(), both on Windows Server 2022, but from the two different Julia builds, and compare the library list? I think what you did just now is to compare the same Julia build but on two different versions of Windows.

@inkydragon
Copy link
Member

inkydragon commented Oct 5, 2022

Some bad news: I tested 1.8.2 and 1.6.7 and they both throw errors (on Win srv).

This is strange, because I tested 1.8.2 earlier and it worked fine.
Maybe I messed up some global state.


I have another guess, maybe we did something wrong, but win 10 doesn't throw an error.
After clearing the clipboard, the clipboard is not available for the unicode format we need.

clipboard("something")
clipboard() == "something"
ccall((:OpenClipboard, "user32"), stdcall, Cint, (Ptr{Cvoid},), C_NULL) == 0 && Base.windowserror("OpenClipboard")
try
    ccall((:EmptyClipboard, "user32"), stdcall, Cint, ()) == 0 && Base.windowserror("EmptyClipboard")
finally
    ccall((:CloseClipboard, "user32"), stdcall, Cint, ()) == 0 && Base.windowserror("CloseClipboard")
end

# If available, the return value is nonzero.
ccall((:IsClipboardFormatAvailable, "user32"), stdcall, Cint, (UInt16,), UInt16(13))
clipboard()

@staticfloat
Copy link
Member Author

So sounds like you can reproduce this on windows server, even with the official binaries? So does that mean that this comment was incorrect?

@inkydragon
Copy link
Member

So sounds like you can reproduce this on windows server, even with the official binaries?

Yes. After restarting the server, I can still reproduce the issue with official x64 binaries 1.0.5, 1.6.7, 1.8.2 and 1.8.2-x86.

So does that mean that #46981 (comment) was incorrect?

Yes, although at the moment I still don't know why it didn't report an error when I tried it before.

@inkydragon
Copy link
Member

inkydragon commented Oct 6, 2022

I tried python, and after emptying the clipboard, trying to get the clipboard again results in an error.

# pip install pywin32
import win32clipboard
import win32con


def setClip(s):
    win32clipboard.OpenClipboard()
    win32clipboard.SetClipboardData(win32con.CF_UNICODETEXT, s)
    win32clipboard.CloseClipboard()

def emptyClip():
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.CloseClipboard()

def getUnicode():
    win32clipboard.OpenClipboard()
    data = None
    try:
        data = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
    finally:
        win32clipboard.CloseClipboard()
    return data

setClip('test')
assert 'test' == getUnicode()
emptyClip()
getUnicode()
getUnicode()

Win 10 and Win server both give the same output:

>>> setClip('test')
>>> assert 'test' == getUnicode()
>>> emptyClip()
>>> getUnicode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in getUnicode
TypeError: Specified clipboard format is not available
>>> getUnicode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in getUnicode
TypeError: Specified clipboard format is not available
>>>

So maybe throwing an error is a normal behavior?

If so, we just need to check if the data is available before getting the clipboard data, and return the empty string or nothing if it is not available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci Continuous integration system:windows Affects only Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants