tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Kolinko <knst.koli...@gmail.com>
Subject Re: mod_jk failed to map shared memory with errno=5
Date Thu, 20 Nov 2014 00:54:19 GMT
2014-11-19 12:47 GMT+03:00 Nan Ge <genan.zh@gmail.com>:
> I'm using Apache-httpd-2.4.10(Win64) and apache-tomcat-8.0.12-windows-x64
> with tomcat-connectors-1.2.40-windows-x86_64-httpd-2.4.x (mod_jk) on
> windows8.1x64 for load balancing, my configuration about mod_jk in
> httpd.conf:
>
> LoadModule    jk_module  modules/mod_jk.so
> JkWorkersFile conf/workers.properties
> JkLogLevel    info
> JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
> JkLogFile     logs/httpd/mod_jk.log
> JkShmFile     logs/mod_jk.shm
> JkMount  /myapp/* lb
>  <Location /jkmanager/>
>     JkMount jkstatus
>     Order deny,allow
>     Deny from all
>     Allow from 127.0.0.1
>  </Location>
>
> and here is my workers.properties:
> worker.list= lb,jkstatus
> worker.jkstatus.type=status
> worker.lb.type=lb
> worker.lb.balance_workers=tm1,tm2
> worker.tm.type=ajp13
> worker.tm.host=127.0.0.1
> worker.tm.lbfactor=1
> worker.tm1.reference=worker.tm
> worker.tm2.reference=worker.tm
> worker.tm1.port=8009
> worker.tm2.port=8010
>
> After apache was started, I cannot open the /jkmanager page, I checked the
> logs/ directory and no mod_jk.shm file was found, and I checked
> mod_jk.log with following error :
>
> [Wed Nov 19 15:40:20 2014] [4296:8648] [info] init_jk::mod_jk.c (3383):
> mod_jk/1.2.40 initialized
> [Wed Nov 19 15:40:20 2014] [4296:8648] [error] jk_shm_open::jk_shm.c (240):
> Failed to map shared memory
> F:/server/httpd-2.4.10-x64-vc11/Apache24/logs/mod_jk.shm with errno=5
> [Wed Nov 19 15:40:20 2014] [4296:8648] [error] init_jk::mod_jk.c (3366):
> Initializing shm:(null) errno=5. Load balancing workers will not function
> properly.
> ...
>
> It seems that mod_jk could not create mod_jk.shm file

Looking at the source code:

1) The doc [1] say that JkShmFile option is "Used only on unix platforms."

The actual code is that
a) On unix platforms it is used always, as documented.

If no JkShmFile is specified then a warning is printed and the default
name "logs/jk-runtime-status" is used.

b) On Windows this feature can be used.
It is disabled by default and used only if JkShmFile is set explicitly.

Question 1: Do you need JkShmFile at all.

Fixme: If you (or anyone else) succeed in using JkShmFile on Windows
then I think the doc shall be updated to mention the use on Windows.

On Windows:
If JkShmFile is not set then it results in allocating some block of
memory without any special properties.

If JkShmFile is set then it does the work with mapped files
(CreateFileMapping and other Win API methods)


2) The CreateFileMapping method that is used to initialize memory
mapping is called in jk_shm.c as

            jk_shm_map = CreateFileMapping(INVALID_HANDLE_VALUE,
                                           jk_get_sa_with_null_dacl(),
                                           PAGE_READWRITE,
                                           0,
                                           (DWORD)shmsz,
                                           shname);

See [2] for documentation. Note that
- hFile is INVALID_HANDLE_VALUE
- shname is "Global/" + some string created from filename.
- shmsz is the size that you specified in configuration as JkShmSize.
By default it is calculated automatically, it is usually recommended
to allow it to be calculated automatically.

It means that:
a) That value of hFile means that there is no "mod_jk.shm" file here.
The mapping is allocated from the system page file.

Question 2: Do you have system page file enabled? (I think that some
systems may have it disabled).


It it is not a file, then you can simplify your configuration: Remove
the "logs/" prefix from the name.

3) There may also be some Windows-specific issues, like security
restrictions etc. Some are mentioned in [2].

Is "jk_get_sa_with_null_dacl()" used in CreateFileMapping() call a
correct value?

GetLastError() returning 5 means ERROR_ACCESS_DENIED - from [3].



Fixme: Can the error message be improved? There is no actual file
here, but it mentions a file name. It is a bit misleading (as one
thinks that it tires to access a file), but it is good as it mentions
the value that actually exists in configuration.
It also does not mention how many bytes it tried to allocate.
It can be something like "Failed to allocate xxx bytes for shared
memory named yyy.  GetLastError returned zzz".

[1] http://tomcat.apache.org/connectors-doc/reference/apache.html

[2] MSDN - CreateFileMapping function
http://msdn.microsoft.com/en-us/library/windows/desktop/aa366537%28v=vs.85%29.aspx

[3] MSDN - System Error Codes
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381%28v=vs.85%29.aspx


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message